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---
{"GetDataResult":{"ID":8,"Name":"Foo Bar"}} Working Link - 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 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.
I guess this is probably what you mean:
user = json.getJSONArray(TAG_USER);
JSONObject c = user.getJSONObject(0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.