Parsing the data and SpringIOC achieved between the underlying

1. parsing JSON

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.43</version>
</dependency>
    static String jsonStr = "{\n" +
            "\t\"sites\": [{\n" +
            "\t\t\"name\": \"百度\",\n" +
            "\t\t\"url\": \"www.baidu.com\"\n" +
            "\t}, {\n" +
            "\t\t\"name\": \"百度网盘\",\n" +
            "\t\t\"url\": \"http://www.baiduyun.com/\"\n" +
            "\t}]\n" +
            "}";

    public static void main(String[] args) {
        JSONObject jsonObject = new JSONObject();

        //
jsonObject.parseObject (jsonStr);
        
        the JSONObject jsonStrObject =first string to a parsed//        JSONArray jsonArray = jsonStrObject.getJSONArray("sites");
        System.out.println(jsonArray.toString());
        for (Object object : jsonArray) {
            JSONObject stObject = (JSONObject) object;
            String name = stObject.getString("name");
            String url = stObject.getString("url");
            System.out.println(name + "---" + url);
        }
    }

}

Assembly JSON

XML parsing

 

Guess you like

Origin www.cnblogs.com/itcastwzp/p/10971746.html