[英]Android not parsing JSON Array
我目前正在嘗試解析代碼中的JSON數組,但問題是它從未進入try塊。
這是我的代碼:
protected Void doInBackground(Void... arg0) {
JsonParser jsonParser = new JsonParser();
String json = jsonParser.getJSONFromUrl("http://hills.ccsf.edu/~jpark41/ViB/sample.json");
if(json != null) {
Log.i("JSON: ", "NOT NULL"); // This log executes!!
try
{
Log.i("we: ", " out here"); // This does not!!
JSONObject jObj = new JSONObject(json);
JSONArray jsar = new JSONArray(json);
Iterator<String> iter = jObj.keys();
while (iter.hasNext()) {
String key = iter.next();
try {
JSONObject value = (JSONObject)jObj.get(key);
id = value.getString("id");
thumb = value.getString("thumb");
media = value.getString("media");
title = value.getString("title");
} catch (JSONException e) {
// Something went wrong!
}
now_playing = id;
earned = title;
}
} catch (JSONException e) {
Log.i("we NOT: ", " out here");
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
永遠不會記錄“我們不在這里”,只有“我們不在這里”。 為什么try塊永遠不會執行? 我沒有用Android解析JSON的豐富經驗,所以我確定我只是缺少一些東西。 謝謝你的幫助。
當我注釋掉JSONObject jObj = new JSONObject(json); 並將迭代器換成一個基本的for循環,所有這些都起作用了。 謝謝大家的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.