JAva/Android errorシリーズ01:Value of type org.json.JSOnObject cannot be converted to JSOnArray
公式提供:JSOnObjectを使用してjsonデータを解析する時報エラー:Value of type org.json.JSOnObject cannot be converted to JSOnArray
一般的に得られるjson戻りデータ:jsonData解析は以下の通りである:
分析の原因は:私のjsonデータを返してただ1つの時(簡単な登録情報のようです)例えば:{“name”:“aaa”,“id”:12},慣用的な思惟はJSOnArrayを利用して解析することができなくて、当然です:JSOnObject!上記の慣用方法は,多数の重複型を持つjson objectの解析であるべきである.慣性的に考えてはいけない.
いいと思うよ~
一般的に得られるjson戻りデータ:jsonData解析は以下の通りである:
private void parseJSONWithJSONObject(String jsonData){
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(jsonData);
for(int i=0; i"id");
String name = jsonObject.getString("name");
} catch (JSONException e) {
e.printStackTrace();
}
}
}
>>>
分析の原因は:私のjsonデータを返してただ1つの時(簡単な登録情報のようです)例えば:{“name”:“aaa”,“id”:12},慣用的な思惟はJSOnArrayを利用して解析することができなくて、当然です:JSOnObject!上記の慣用方法は,多数の重複型を持つjson objectの解析であるべきである.慣性的に考えてはいけない.
JSONObject jsonObject = new JSONObject(responsebody);
status = jsonObject.getString("status");
message =jsonObject.getString("msg");
いいと思うよ~