Parse JSON with unknown key?

后端 未结 2 914
慢半拍i
慢半拍i 2021-01-20 16:52

i have a Json output like this :

The numbers 2922 and 3910 are random numbers. How can i store all values that are in \"name\" in an array?

Thank yo

2条回答
  •  心在旅途
    2021-01-20 17:06

    You can use the jackson tool to conver json to pojo Below is the snippet of code

    public void parse(String json)  {
           JsonFactory factory = new JsonFactory();
    
           ObjectMapper mapper = new ObjectMapper(factory);
           JsonNode rootNode = mapper.readTree(json);  
    
           Iterator> fieldsIterator = rootNode.fields();
           while (fieldsIterator.hasNext()) {
    
               Map.Entry field = fieldsIterator.next();
               System.out.println("Key: " + field.getKey() + "\tValue:" + field.getValue());
           }
    }
    

    HapPy C@ding..!!

提交回复
热议问题