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);