在拿JSON數據我得到錯誤:JSONArray不能被轉換爲JSONObject的錯誤
JSONArray cannot be converted to JSONObject
代碼JSON生成:
JSONObject parent = new JSONObject();
DatabaseHandler dbh = new DatabaseHandler(getApplicationContext());
for(int i=0; i < allEds.size(); i++){
String edsText = allEds.get(i).getText().toString();
//spinner = allSpns.get(i);
String spinSelected=allSpns.get(i).getSelectedItem().toString();
try
{
JSONObject json = new JSONObject();
json.put("Id", i);
json.put("FieldName", edsText);
json.put("FieldType",spinSelected);
parent.accumulate("data", json);
}
catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Generated json is
{"data":
[{"FieldType":"Account Number","FieldName":"r","Id":0},
{"FieldType":"Net Banking Id","FieldName":"tt","Id":1}
]}
code for json read
------------------
JSONObject jsonObj = new JSONObject(folderStructure);
JSONObject data = jsonObj.getJSONObject("data");
String id = data.getString("Id");
String value = data.getString("FieldName");
Log.d("Item name: ", value);
在閱讀上面的JSON會收到錯誤 任何一點毛病用代碼?
添加代碼。 – jeet
@jeet增加了你的 – user1682133
你放置你的json代碼...在JavaScript中? –