我想從jason webservice
獲取數據獲取數據,可能無法從JSON Web服務
JSON的反應是:
{"content":[{"id":"1","asset_id":"62","title":"sample page","alias":"","introtext":"","fulltext":"Some Contents"},{"id":"2","asset_id":"62","title":"sample page2","alias":"","introtext":"","fulltext":"Some Contents"},{"id":"3","asset_id":"62","title":"sample page3","alias":"","introtext":"","fulltext":"Some Contents"}]}
參觀Here 我已經在這樣做了之後:
private void parseData() {
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(BASE_URL);
try {
// Getting Array of Contents
contents = json.getJSONArray(TAG_CONTENTS);
// looping through All Contents
for(int i = 0; i < contents.length(); i++){
JSONObject c = contents.getJSONObject(i);
// Storing each json item in variable
id = c.getString(TAG_ID);
title = c.getString(TAG_TITLE);
}
textView.setText(id + " " + title);
} catch (JSONException e) {
e.printStackTrace();
}
}
現在我得到了id = 3
和title = sample page3
結果現在我怎麼能得到前兩個值作爲也!!?
這是怎麼回事?什麼是錯誤? – 2013-03-03 08:50:38
沒有任何錯誤,但結果也沒有顯示! – 2013-03-03 08:52:56
你確定你沒有結束例外嗎?如果是這樣,請提供你的堆棧跟蹤,並且不要讓你的catch部分空着,你應該處理這個異常。 – Triode 2013-03-03 08:58:36