1.json Cannot deserialize instance of `java.util.ArrayList<com.uj.toolmanager.parambase.entity.SysParam>` out of START_OBJECT token
表明远程调用返回的是一个object对象,而客户端却用了一个列表来接收。
2.Exception in thread "main" com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.uj.toolmanager.parambase.entity.SysParam` out of START_ARRAY token
表明远程调用返回的是一个数组对象,而客户端却用了一个对象来接收。
3.要正常解析json字符串或者数据要使用专门的工具类,
objectMapper解析数组
String json3="[\n" +
" {\n" +
" \"workshop\": 483,\n" +
" \"productLine\": 484,\n" +
" \"orgId\": 1,\n" +
" \"itemCode\": \"helperName\",\n" +
" \"itemSubname\": \"辅料1\",\n" +
" \"itemSort\": 0,\n" +
" \"itemUserCode\": \"1111\",\n" +
" \"isGobal\": 1,\n" +
" \"remark\": \"1\"\n" +
"},\n" +
"{\n" +
" \"workshop\": 483,\n" +
" \"productLine\": 484,\n" +
" \"orgId\": 1,\n" +
" \"itemCode\": \"helperName\",\n" +
" \"itemSubname\": \"辅料1\",\n" +
" \"itemSort\": 0,\n" +
" \"itemUserCode\": \"1111\",\n" +
" \"isGobal\": 1,\n" +
" \"remark\": \"1\"\n" +
"}]";
ObjectMapper objectMapper = new ObjectMapper();
// Map<String, Object> stringList = objectMapper.readValue(json3, new TypeReference<Map<String,Object>>() {});
List<SysParam> stringList = objectMapper.readValue(json3, new TypeReference<List<SysParam>>() {});
// Integer o = (Integer) stringList.get("code");
// SysParam sysParam = stringList.get(0);
System.out.println(stringList);
objectMapper解析字符串
public static void main(String[] args) throws JsonProcessingException {
String json2="{\"code\":500,\"data\":{\"addressArea\":1,\"addressCity\":1,\"addressDetail\":\"123\",\"adressProvince\":1,\"contractPhone\":\"18866665555\",\"contractUser\":\"e\",\"createTime\":1566806029000,\"createUserId\":-1,\"eMail\":\"12@qq.com\",\"isDeleted\":0,\"mdKey\":null,\"netAddress\":\"xxx\",\"orgChannel\":\"org_channel\",\"orgId\":1,\"orgLogoUrl\":\"/images/20240628/966484267766906880.png\",\"orgName\":\"1\",\"orgShortName\":\"1\",\"orgType\":1,\"phone\":\"0571-xxxxxxxx\",\"smallLogoUrl\":\"aliyuncs.\",\"status\":0,\"updateTime\":1661526859000,\"updateUserId\":1},\"resultMsg\":\"加载完成\"}";
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> stringList = objectMapper.readValue(json2, new TypeReference<Map<String,Object>>() {});
Integer o = (Integer) stringList.get("code");
System.out.println(o);
}