저는 현재 일부 구형 코드를 json 객체로 변환해야하는 프로젝트에서 작업하고 있습니다. 결과를 SQL 쿼리에서 가져 와서 json으로 반환하는 범주를 반환합니다. 나는 자바 스크립트에 정통한 사람이 아니기 때문에 json 만 알면, 이것에 대해 가장 간단한 방법은 무엇인지 모르겠습니다. 여기html을 Json 객체로 변환하기
function createOutputCategories(){
try
{
output =
"<html>" +
"<head>" +
"<title>" +
"You can find it!" +
"</title>" +
"</head>" +
"<body bgcolor='#CED3F3'>" +
"<a href='" + url + "file.xsjs?parent=1'>" +
"</a>" +
"<br><br>";
if(parent === "1"){
output = output + "<h3><font color='#AAAAAA'>Home</font>";
}else{
output = output +"<a href='javascript:history.back()'>" +
"<h3>Back";
}
output = output +
"</h3>" +
"</a>" +
"<h1>" +
"Categories:" +
"</h1>";
while(rs.next()){
if(rs.getString(3) === 0 || rs.getString(3) === null || rs.getString(3) === undefined || rs.getString(3) === "0"){
output = output + "<br><a href='" + url + "yeti.xsjs?parent=" + rs.getString(1) + "'>" + rs.getString(2) + "</a>";
}else{
output = output + "<br><a href='" + url + "yeti.xsjs?parent=" + rs.getString(1) + "'>" + rs.getString(3) + "</a>";
}
}
}catch(Exception){
$.response.contentType = "text/plain";
$.response.setBody("Failed to retreive data");
$.response.status = $.net.http.INTERNAL_SERVER_ERROR;
}
내가 지금까지 가지고 있지만 유효한 JSON 개체를 반환하고 있지 않다 무엇인가 : 내가 무엇을하시기 바랍니다 제공해야하는 경우
function createOutputCategories(){
try{
output =
"category: {name = \"" + parent + "\"; description = \"\"}";
output = output +
"subcategories: [ ";
while(rs.next()){
output = output +
"{ catid = \"" + rs.getString(1) + "\"; catname = \"" + rs.getString(2) + "\"; altname = \"" + rs.getString(3) + "\"; description = \"" + rs.getString(4) + "\"}";
}
output = output +
"];";
}
catch(Exception){
$.response.contentType = "text/plain";
$.response.setBody("Failed to retreive data");
$.response.status = $.net.http.INTERNAL_SERVER_ERROR;
}
을 여기에 내가 JSON으로 변경해야하는 기능입니다 알려줘! 감사!
당신은 고전적인 자바 스크립트 객체를 구축 Should'nt을 다음 JSON.stringify을 사용할 수 있습니까? –
이것을 확인해보십시오 : http://json.fastfrag.org/ –
@SteveB 저는 제가 지금까지 알고있는 것을 적용해서이 작업을하고 싶습니다. 객체를 만드는 것이 이상적 일지 모르지만 나는 할 수 없었습니다. 이걸 제대로 수행하십시오 –