JSON 数据的详细解析方法第一步,首先根据网址获取 JSON 格式的字符串,方法如下: 以下方法的返回值就是 JSON 格式的字符串!!! 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、 String strurl_1 = "./telematics/v3/weather?location= 北京&output=json&ak=5slgyqGDENN7Sy7pw29IUvrZ";// 北京的天气接口。 public String connServerForResult(String strUrl) { // HttpGet 对象 HttpGet httpRequest = new HttpGet(strUrl); String strResult = ""; try { // HttpClient 对象 HttpClient httpClient = new DefaultHttpClient(); HttpParams params = (); // 请求超时 5秒接受超时 5秒 (params, 5000); (params, 5000); // 获得 HttpResponse 对象 HttpResponse httpResponse = (httpRequest); if (().getStatusCode() == ) { // 取得返回的数据 strResult = (()); } else { return strResult; }} catch (ClientProtocolException e){ ("protocol error"); (); } catch (IOException e){ ("IO error"); (); } return strResult; }、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、第二步, 通过上面的方法已经获得了 JSO N 格式的字符串,假设 String strResult=connServerForResult(strurl_1) ; 下面虚线中的的字符串就是根据实际运行获得的 JSON 格式的字符串 strResult : 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、{ "error":0, "status":"ess", "date":"2014-04-01", "results":[ { "currentCity":"\u5317\u4eac", "weather_data"
JSON数据的详细解析方法 来自淘豆网m.daumloan.com转载请标明出处.