[英]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.