![](/img/trans.png)
[英]Android asynctask json parsing getting error android.os.NetworkOnMainThreadException
[英]Android AsyncTask with JSON Parsing error
本節中出現錯誤:
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);
}
}
------- Web服務結果---
{ “GetDataResult”:{ “ID”:8, “名”: “富酒吧”}}工作鏈接- http://127.0.0.1/WcfService4/Service1.svc/getData/?key=8
提供更好的解決方案。
看來您沒有使用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"));
}
看來問題出在本節:
user = json.getJSONArray(TAG_USER);
JSONObject c = json.getJSONObject(0);
您獲得了JOSNObject user
但從未使用過它。
我想這可能是您的意思:
user = json.getJSONArray(TAG_USER);
JSONObject c = user.getJSONObject(0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.