JSON解析

JSONObject解析方式

......
    JSONArray jsonArray = new JSONArray(jsonData);
    for(int i=0;i<jsonArray.length();i++){
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        String id = jsonObject.getString("id");
        String name = jsonObject.getString("name");
        String version = jsonObject.getString(''version");
......

GSON解析方式

1、在app/build.gradle中添加依赖

  compoile 'com.google.code.gson:gson:2.7'

2、创建一个类,设置所有属性的getter和setter

3、将JSON数据解析成一个对象

  Gson gson = new Gson();

  Person person = gson.fromJson(jsonData,Person.class);

  数组:List<Person> people = gson.gromJson(jsonData,new TypeToken<List<Person>>(){}.getType());

4、通过for循环取出所有数据

原文地址:https://www.cnblogs.com/yl-saber/p/6421912.html