我正在處理其中發送請求ot服務器獲取JSON數組字符串的項目。我正在使用下面的java代碼來創建一個JSON數組列表字符串。無法解析JSON數組字符串
[{"duration":12222‚"height":12‚"widht":12‚"filePath":30‚"format":123‚"bitRate":1111‚"exe":"m"}‚{"duration":12222‚"height":12‚"widht":12‚"filePath":30‚"format":123‚"bitRate":1111‚"exe":"m"}‚{"duration":12222‚"height":12‚"widht":12‚"filePath":30‚"format":123‚"bitRate":1111‚"exe":"m"}‚{"duration":12222‚"height":12‚"widht":12‚"filePath":30‚"format":123‚"bitRate":1111‚"exe":"m"}]
當我使用JQuery如下解析它:
JSONArray itemList = new JSONArray();
for(int i =0; i<4; i++) {
String exe = "m";
final JSONObject jsonObj = new JSONObject();
jsonObj.put("filePath", 30);
jsonObj.put("duration", 12222);
jsonObj.put("bitRate", 1111);
jsonObj.put("widht", 12);
jsonObj.put("format", 123);
jsonObj.put("height", 12);
jsonObj.put("exe", exe);
JSONObject jObject = new JSONObject();
try {
itemList.put(jsonObj);
// jObject.put("itemList", itemList);
} catch (Exception e) {
System.out.println("ERROR");
}
}
return itemList.toString();
在客戶機側,在AJAX響應,我通過使用上述方法得到下面的字符串
$jQ.each($jQ.parseJSON(responseJSON), function(idx, obj) {
alert(obj.filePath);
});
我得到JS錯誤爲JSON.parse: expected property name or '}'
我不明白爲什麼這個錯誤是occ uring。
在契約中有你的JSON錯誤,粘貼JSON這裏 - > http://jsonlint.com/ 你會發現爲什麼 – Defoncesko
你得到JSON是JavaScript的OBJ ...你沒必要解析它我認爲 – VostanAzatyan
您的JSON無效...... – VostanAzatyan