简体   繁体   中英

Which class of Jackson library should I use to parse JSON data?

My JSON data:

[  
   "Gi 1/1",
   {  
      "Shutdown":true,
      "Speed":"force10ModeFdx",
      "AdvertiseDisabled":0,
      "MediaType":"dual",
      "FC":"off",
      "MTU":9600,
      "ExcessiveRestart":false,
      "PFC":0
   }
]

Controlller class method:

public @ResponseBody void setSwitchPortInterfaceInfo(@RequestBody JsonNode jsonNode) 
    throws JsonProcessingException, IOException { }

When calling this method only "Gi 1/1" got parsed.

Which class do I need to pass as argument to parse complete JSON object?

The JSON Data represent in the question is not present in correct format. We need to convert it into proper version than only parse the Same.

Ideal way of declaring JSON structure is:

[{"key":"value"},{"key":"value"},{"key":"value"}]
ObjectMapper objectMapper = new ObjectMapper();

String strToParse = getString(); // put the string you want to parse
JsonNode node = objectMapper.readValue(strToParse, JsonNode.class);
System.out.println(node.get(0)); 
System.out.println(node.get(1));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM