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);
        }
        }
相關文章
相關標籤/搜索