解析Json和复合类型

//解析单数据类型 private void parseJSONWithJSONObject(String jsonData) { try { JSONObject jsonObject = new JSONObject(jsonData); String id = jsonObject.getString("id"); String version = jsonObject.getString("version"); String name = jsonObject.getString("name"); textView.setText(id + " " + version + " " + name); } catch (JSONException e) { e.printStackTrace(); } } //解析复合数据类型 private void parseJSONObjectOrJSONArray(String jsonData) { try { String count = ""; JSONObject jsonObject = new JSONObject(jsonData); JSONArray jsonArray = jsonObject.getJSONArray("list"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject1 = jsonArray.getJSONObject(i); String id = jsonObject.getString("id"); String version = jsonObject.getString("version"); String name = jsonObject.getString("name"); count = id + " " + version + " " + name; } textView.setText(count); } catch (JSONException e) { e.printStackTrace(); } }
原文地址:https://www.cnblogs.com/327999487heyu/p/5720496.html