-2
提取的JSONObject我想從這個jsonarray只讀「價值」對象如何從JSONArray android的
"body":{"und":[{"value":"hi friends!!!","summary":null,"format":null}]}
這是我的代碼:
protected void onPostExecute(final JSONObject result) {
try {
TextView lst2 = (TextView) findViewById(R.id.View2);
JSONArray cast = result.getJSONArray("body");
for (int i=0; i<cast.length(); i++) {
JSONObject actor = cast.getJSONObject(i);
String name = actor.getString("value");
lst2.setText(name);
}
} catch (Exception e2) {
Log.v("Error adding article", e2.getMessage());
}
}
JSONObject的結果是從休息響應服務器。
見這個例子中,如果有幫助:http://stackoverflow.com/問題/ 32092668/acess-nested-object-of-json-in-java/32093501#32093501 –
你的代碼中有什麼/沒有發生?此外,將文本設置爲像這樣的循環只會將其設置爲最後一個值(即無論在'cast.getJSONObject(cast.length()-1)' – codeMagic
「body」:{「und」:[{「價值「:」嗨朋友!!!「,」摘要「:null,」format「:null}]}這是無效的jason。 –