获取json中data的数据

获取json中data的数据

 

package com;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
 
public class Yuma
{
    public static void main(String[] args)
    {
        String json = "{\"data1\":[{\"name\":\"aa\",\"age\":\"12\"},{\"name\":\"bb\",\"age\":\"13\"}],\"data2\":{\"nowpage\":1,\"pagesize\":2}}";
        JSONObject object = JSONObject.parseObject(json);
        JSONArray array = object.getJSONArray("data1");
        for(int i = 0; i < array.size(); i++)
        {
            JSONObject o = array.getJSONObject(i);
            System.out.println(o.get("age"));
            System.out.println(o.get("name"));
        }
    }
}

 

你可能感兴趣的:(Java)