[英]Android AsyncTask with JSON Parsing error
Error coming in this section: 本节中出现错误:
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 Result--- ------- Web服务结果---
{"GetDataResult":{"ID":8,"Name":"Foo Bar"}} Working Link - http://127.0.0.1/WcfService4/Service1.svc/getData/?key=8 { “GetDataResult”:{ “ID”:8, “名”: “富酒吧”}}工作链接- http://127.0.0.1/WcfService4/Service1.svc/getData/?key=8
Provide the better solution for solving this. 提供更好的解决方案。
It seems you havn't use your JSONArray object 看来您没有使用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"));
}
It seems like that the problem comes from this section: 看来问题出在本节:
user = json.getJSONArray(TAG_USER);
JSONObject c = json.getJSONObject(0);
you get a JOSNObject user
but you never used it. 您获得了JOSNObject user
但从未使用过它。
I guess this is probably what you mean: 我想这可能是您的意思:
user = json.getJSONArray(TAG_USER);
JSONObject c = user.getJSONObject(0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.