OkHttpClient okHttpClient=new OkHttpClient(); Request request=new Request.Builder().url("http://10.0.2.2/date.json").build(); try { Response response=okHttpClient.newCall(request).execute(); final String date=response.body().string(); runOnUiThread(new Runnable() { @Override public void run() { tView.setText(date); } }); parseJSONWithJSONObject(date); } catch (Exception e) { e.printStackTrace(); }
private void parseJSONWithJSONObject(final String date) { try { Log.i("TAG", "--1--"); JSONArray jsonArray = new JSONArray(date);--到这不执行下去了 Log.i("TAG", "--2--"); for (int i = 0; i < jsonArray.length(); i++) { Log.i("TAG", "--3--"); JSONObject jsonObject = jsonArray.getJSONObject(i); final String id = jsonObject.getString("id"); String version = jsonObject.getString("version"); String name = jsonObject.getString("name"); Log.i("TAG", "id:"+id+"name:"+name+"version"+version); } } catch (Exception e) { e.printStackTrace(); } }
解析json数据执行到第二段代码的 JSONArray jsonArray = new JSONArray(date);就不执行下去了,求指导什么原因?
解决方案
50
那就没毛病呀
25
最外层应该还有个key 如:result:[]
25
最外层应该还有个key 如:result:[]
这个对,最好在包一层data