JSON数据解析

来源:互联网 发布:淘宝手机端轮播图尺寸 编辑:程序博客网 时间:2024/05/17 23:28

JSON返回示例:

{    "resultcode":"200",    "reason":"Successed!",    "result":{        "lat":"39.915065193348",        "lng":"116.40389843345",        "type":"1",        "address":"北京市东城区中华路甲10号",        "business":"天安门",        "citycode":131    }}

JSON解析如下:

//以下是发送网络请求JSON数据HttpClient httpClient = new DefaultHttpClient();HttpGet httpGet = new HttpGet(url.toString());HttpResponse httpResponse = httpClient.execute(httpGet);            if(httpResponse.getStatusLine().getStatusCode()==200){    HttpEntity entity = httpResponse.getEntity();    String response = EntityUtils.toString(entity, "utf-8");    //以下是对JSON数据进行解析                        JSONObject jsonObject = new JSONObject(response);    JSONObject result = jsonObject.getJSONObject("result");             String location= result.getString("address");}

JSON返回示例:
{“response”:{“data”:[{“address”:”南京市游乐园”,”province”:”江苏”,”district”:”玄武区”,”city”:”南京”}]},”status”:”ok”}

JSON解析如下:

JSONObject  dataJson=new JSONObject("你的Json数据“);JSONObject  response=dataJson.getJSONObject("response");JSONArray data=response.getJSONArray("data");JSONObject info=data.getJSONObject(0);String province=info.getString("province");String city=info.getString("city");String district=info.getString("district");String address=info.getString("address");System.out.println(province+city+district+address);
0 0
原创粉丝点击