I am having a problem in making a json in java. below is the JSON which I have to create through java code.
{"status":"0",
"Response":{
"abc":[
"def":[
"fgh":[
{
"abc":"abc",
"def":"abc",
"ghi":"abc",
},
{
"abc":"abc",
"def":"abc",
"ghi":"abc",
},
{
"abc":"abc",
"def":"abc",
"ghi":"abc",
}
],
"ghi":[
{
"abc":"abc",
"def":"abc",
"ghi":"abc",
},
{
"abc":"abc",
"def":"abc",
"ghi":"abc",
},
{
"abc":"abc",
"def":"abc",
"ghi":"abc",
}
]
]
]
]
}
}
and here is the java code.
JSONObject result = new JSONObject();
JSONObject abcObject = new JSONObject();
JSONArray resultArray = new JSONArray();
JSONArray fghArray = new JSONArray();
JSONArray defArray = new JSONArray();
JSONArray abcArray = new JSONArray();
abcObject.put("abc");
abcObject.put("def");
abcObject.put("ghi");
fghArray.add(abcObject);
defArray.add(fghArray);
abcArray.add(defArray);
result.put("status", 0);
result.put("Response",abcArray);
return resultJson.toString();
The Problem:
when i send back the json to a jsp. the output is not showing up.
success:function(data) {
alert(data);
var json = $.toJSON(data);
alert(json);
},
alert(data) is alerting an object and 2nd alert alert(json) is not showing anything.
property:valuesyntax of object literals.)name:valuepairs inside square brackets, so the arrays beginning on the third and fourth lines of your would-be JSON are invalid.