2015-06-15 143 views
0

錯誤本節來臨:的Android的AsyncTask與JSON解析錯誤

protected void onPostExecute(JSONObject json) { 
    try { 
     // Getting JSON Array 
     user = json.getJSONArray(TAG_USER); 
     JSONObject c = json.getJSONObject(0); 
     String id = c.getString(TAG_ID); 
     String name = c.getString(TAG_NAME); 
     Log.i("id",id); 
    } 
} 

------- Webservice的結果---

{ 「GetDataResult」:{ 「ID」:8,「Name」:「Foo Bar」}} Working Link - http://127.0.0.1/WcfService4/Service1.svc/getData/?key=8

提供解決此問題的更好解決方案。

+3

是不是127.0.0.1本地主機?我們應該如何訪問該鏈接? – Gosu

+2

「爲解決這個問題提供更好的解決方案」..所以,現在StackOverflow爲你工作吧.. – Gosu

回答

1

看來你沒有帶用你的JSONArray對象

JSONArray mainfoodlist = null; 


    tipshealth = json.getJSONArray(TAG_RESPONSE); 

     // looping through All RESPONSE 
     for (int i = 0; i < tipshealth.length(); i++) { 
     JSONObject jsonobj = tipshealth.getJSONObject(i); 
     tipHealth = jsonobj.getString(KEY_HEALTHTIPS); 

     listhealthtips.add(tipshealth.getJSONObject(i).getString("tips")); 

     } 
0

這似乎是這個問題來源於此節:

user = json.getJSONArray(TAG_USER); 
JSONObject c = json.getJSONObject(0); 

你得到一個JOSNObject user,但你從來沒有使用過。

我猜這可能是你的意思:

user = json.getJSONArray(TAG_USER); 
JSONObject c = user.getJSONObject(0);