这是我从URL解析json的代码:
public JSonObject getJSonFromUrl(String url) {try { // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); json = EntityUtils.toString(httpEntity);} catch (UnsupportedEncodingException e) { e.printStackTrace();} catch (ClientProtocolException e) { e.printStackTrace();} catch (IOException e) { e.printStackTrace();}JSonObject jObj;// try parse the string to a JSON objecttry { jObj = new JSonObject(json);} catch (JSonException e) { Log.e("JSON Parser", "Error parsing data " + e.toString());}Log.v("debug", "JSON ready to parsing");return jObj;}public void parsingData(JSonObject json) {try { JSonArray data = json.getJSonArray("data"); for (int i = 0; i < data.length(); i++) { // Do your stuff, example : JSonObject c = data.getJSonObject(i); JSonObject topDrops = c.getJSonObject("topDrops"); JSonArray playerArray = topDrops.getJSonArray("player"); // playerArray.getJSonObject(0) == first player }} catch (JSonException e) { e.printStackTrace(); Log.v("debug", "Error during the connection HTTP"); cancel(Boolean.TRUE);}}


