JSON parse error: Cannot deserialize value of type java.util.ArrayList<com.tzy.entity.ComponentOilProperties> from Object value (token JsonToken.START_OBJECT); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.util.ArrayList<com.tzy.entity.ComponentOilProperties> from Object value (token JsonToken.START_OBJECT) at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 1]] 前端以Json格式传递列表时的书写格式错误及解决方案
报错
JSON parse error: Cannot deserialize value of type java.util.ArrayList<com.tzy.entity.ComponentOilProperties> from Object value (token JsonToken.START_OBJECT); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.util.ArrayList<com.tzy.entity.ComponentOilProperties> from Object value (token JsonToken.START_OBJECT) at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 1]]
解决方案
报错的写法
{
"setSettings":
[
{
"name": "chongZheng",
"xinwan": 100,
"liu": 0,
"ben": 0.6,
"xiting": 0,
"midu": 0.8
},
{
"name": "mtbe",
"xinwan": 116.66,
"ben": 3,
"liu": 0,
"xiting": 0,
"midu" : 0.73
},
{
"name": "feiFang",
"xinwan": 74.34,
"liu": 0,
"ben": 0.8,
"xiting": 7,
"midu": 0.67
}
]
}
正确写法
[
{
"name": "chongZheng",
"xinwan": 100,
"liu": 0,
"ben": 0.6,
"xiting": 0,
"midu": 0.8
},
{
"name": "mtbe",
"xinwan": 116.66,
"ben": 3,
"liu": 0,
"xiting": 0,
"midu" : 0.73
},
{
"name": "feiFang",
"xinwan": 74.34,
"liu": 0,
"ben": 0.8,
"xiting": 7,
"midu": 0.67
}
]
不需要写后端接收List的名称
本文详细解释了在前后端交互中遇到的JSON列表解析错误及其正确的书写格式。针对后端无法正确解析前端传递的列表数据的问题,给出了具体的错误示例与解决方案。

4456

被折叠的 条评论
为什么被折叠?



