2.json解析

static String jsonStr = "{\"sites\":[{\"name\":\"gold\",\"url\":\"www.baidu.com\"},{\"name\":\"jlong\",\"url\":\"http://baidu.com/\"}]}";
 
public static void main(String[] args) {
        JSONObject jsonObject = new JSONObject();
        // 将json字符串转为jsonbject
        JSONObject jsonStrObject = jsonObject.parseObject(jsonStr);
        JSONArray jsonArray = jsonStrObject.getJSONArray("sites");
        for (Object object : jsonArray) {
        JSONObject stObject = (JSONObject) object;
        String name = stObject.getString("name");
        String url = stObject.getString("url");
        System.out.println(name + "---" + url);
        }
        }
posted @ 2019-06-03 10:07  Gold_Long  阅读(231)  评论(0编辑  收藏  举报