我应该使用哪一类Jackson库来解析JSON数据?

时间:2021-10-29 20:01:59

My JSON data:

我的JSON数据:

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

Controlller class method:

Controlller类方法:

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

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

调用此方法时,只解析了“Gi 1/1”。

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

我需要将哪个类作为参数传递给解析完整的JSON对象?

2 个解决方案

#1


0  

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.

问题中的JSON数据表示格式不正确。我们需要将其转换为正确的版本而不是仅解析相同的版本。

Ideal way of declaring JSON structure is:

声明JSON结构的理想方式是:

[{"key":"value"},{"key":"value"},{"key":"value"}]

#2


0  

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));

#1


0  

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.

问题中的JSON数据表示格式不正确。我们需要将其转换为正确的版本而不是仅解析相同的版本。

Ideal way of declaring JSON structure is:

声明JSON结构的理想方式是:

[{"key":"value"},{"key":"value"},{"key":"value"}]

#2


0  

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));