当前位置:   article > 正文

前端以Json格式传递列表时的书写格式错误及解决方案_json parse error: cannot deserialize value of type

json parse error: cannot deserialize value of type `java.util.arraylist

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
	    }
	]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
正确写法
[
    {
        "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
    }
]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

不需要写后端接收List的名称

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/739423
推荐阅读
相关标签