[Java] Java traversed JSONObject and JSONARRAY with Fastjson

tags: java  algorithm  fastjson  jsonobject  jsonArray  

public static void parseJson(Object object) {
    if(object instanceof JSONObject) {
        JSONObject jsonObject = (JSONObject) object;
        for (Map.Entry<String, Object> entry: jsonObject.entrySet()) {
            System.out.println(entry.getKey());
            Object o = entry.getValue();
            if(o instanceof String) {
                System.out.println("key:" + entry.getKey() + ",value:" + entry.getValue());
            } else {
                parseJson(o);
            }
        }
    }
    if(object instanceof JSONArray) {
        JSONArray jsonArray = (JSONArray) object;
        for(int i = 0; i < jsonArray.size(); i ++) {
            parseJson(jsonArray.get(i));
        }
    }
    if(object instanceof String || object instanceof Integer) {
        System.out.println(object.toString());
    }

}

Intelligent Recommendation

fastjson of JSONArray and JSONObject

Transfer: http://blog.csdn.net/tangerr/article/details/76217924 Fastjson is a tool of domestic well-known Internet company Alibaba e-commerce developed in-house for java background processing json for...

JSON, JSONOBJECT, JSONARRAY in Fastjson

content Introduction demo Introduction demo plant test   Output result     Refer...

Java-jsonObject to jsonarray, jsonarray to list object

JsonObject to JSONARRAY JSONArray data = JSONArray.parseArray(reqMap.get("userListDto").toString()); JSONObject jsonObj = JSONObject.fromObject(resultMap.get("data")); JSONArray ce...

How to use JSONOBJECT and JSONARRAY in Java

Print output Differences between PUT, Accumulate, Element public object put (Object Key, Object value) maps the value to Key. If this JSONOBJECT object exists, there is a value under this key, the cur...

More Recommendation

HashMap traversed in java, jsonObject traversing

1. HashMap traversal The first use iterator Map map = new HashMap(); Iterator iter = map.keySet().iterator(); while (iter.hasNext()){ } The second type of for each Map<String,String> map = new H...

Java converts jsonarray to jsonobject corresponding to the key value

Sometimes when we manipulate data, a lot of data is in jsonarry format. such as: Such a format is very typed in a tabular data type. But we have to take the name with id 1 so we have to change the var...

Insert JSONObject in the first place in JSONArray in java

Insert JSONObject in the first place in JSONArray in java I found a lot of methods on the Internet that didn't find every JSONObject data inserted in the first place of JSONArray. then, Write one by y...

JSONObject, JSONArray and java entity class conversion

JSONObject, JSONArray and java entity class conversion Under normal circumstances: Convert JSONObject to entity class: Employee employee = JSONObject.toJavaObject(param, Employee.class); Convert JSONA...

Java parsing complex json: the use of JSONObject and JSONArray

Before the formal analysis, we need to download the jar packages needed to parse Json, a total of seven. The download address is as follows: https://download.csdn.net/download/zai_xia/10374080 You can...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top