前端以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]] 前端以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的名称

猜你喜欢

转载自blog.csdn.net/a928108554/article/details/126586783