JSON解析出现了问题,后来发现是数据有问题
原JSON数据如下
重点是一对“{}”括起来的且用逗号隔开的是一个JSONObject,可用get(String s)获取;
凡是用一对“[]”括起来的都是一个JSONArray,其中每一对“{}”是一个get(int i);
{
"Result": "0",
"Message": "请求成功",
"TimeConsuming": "400.682926ms",
"Content": [
{
"StoreBasic": {
"StoreId": "1346",
"StoreName": "迈道夫汽车服务会所丽水路店",
"StorePhone": "4006180571",
"StoreAddress": "丽水路315号",
"StoreLatitude": "30.328516006",
"StoreLongtitude": "120.139701843",
"StoreType": "非4S",
"StoreDistance": "45617",
"StoreImage": "http://i.chexiaodi.com.cn//s/upload/shop_photo_m/2012122714201872409.JPG",
"StoreBigImage": "http://i.chexiaodi.com.cn//s/upload/shop_s_photo/2012122714201872409.JPG",
"StoreIntroduction": "迈道夫汽车服务会所,致力于为尊贵客户及其座驾提供至尊级会员服务。\n会所秉承迈道夫汽车绅士文化理念,独创“1+n”服务模式,在会所内通过多元化的服务项目为汽车和车主提供高品质的服务项目,在会所外凭借移动设备的上门洗车为客户提供高满意的贴心体验。迈道夫汽车服务会所,承载爱车梦想,满足爱车欲望。",
"StoreCommentNum": "0",
"StoreScope": "洗车,美容,保养",
"StoreStar": "0.0",
"StoreBranch": "1",
"StoreServiceTime": "08:00-19:00",
"StoreServiceNum": "0",
"StoreGoodNum": "0",
"StoreAreaCode": "",
"StoreQualification": "1"
},
"ServiceBasic": {
"ServicePrice": "0.00",
"ServiceOnsite": "",
"ServiceId": ""
}
}
],
"Index": "1"
}
解析代码
JSONObject object = new JSONObject(result); JSONArray content = object.getJSONArray("Content"); Log.v("333content",content.toString()); JSONObject basic = content.getJSONObject(0); JSONObject storebasic = basic.getJSONObject("StoreBasic"); Log.v("333basic",basic.toString()); Log.v("333storebasic",storebasic.toString());