我得到了結果json和解析在android中。異常情況下出現一條消息:org.json.JSONException:價格沒有價值org.json.JSONException:沒有價值的價值
W/System.err: org.json.JSONException: No value for price
W/System.err: at org.json.JSONObject.get(JSONObject.java:389)
W/System.err: at org.json.JSONObject.getString(JSONObject.java:550)
我的Java類
JSONParser jsonParser = new JSONParser();
// tracks JSONArray
JSONArray albums = null;
// Album id
String album_id = null;
String song_id = null;
String album_name, song_name, price;
// single song JSON url
// GET parameters album, song
private static final String URL_SONG = "my url";
// ALL JSON node names
private static final String TAG_NAME = "name";
private static final String TAG_PRICE = "price";
private static final String TAG_ALBUM = "name"; // album
...
try {
JSONObject jObj = new JSONObject(json);
if(jObj != null){
song_name = jObj.getString(TAG_NAME);
album_name = jObj.getString(TAG_ALBUM);
price = jObj.getString(TAG_PRICE);
}
}
catch (JSONException e) {
e.printStackTrace();
}
我的JSON網址:
{
"id": "551"
"name": "Rent Disk"
"price": "3233333"
"album_id": "3"
"album": "Michael"
}
如何解決這個異常?非常感謝 !!
您的JSON無效 –
檢查您在本網站JSON嘗試: - HTTP://www.jsoneditoronline .org/ – musica