关于json的格式问题

理想的数据是这样的:
{
“code”: 0,
“msg”: “成功”,
“data”: [
{
“name”: null,
“type”: null,
“foods”: [
{
“id”: “123”,
“name”: “皮皮虾”,
“price”: 6.6,
“description”: “看起来很好吃”,
“icon”: “a.jpg”
}
]
}
]
}
但是实际上数据是这样:
{
“code”: 0,
“msg”: “成功”,
“data”: [
{
“foods”: [
{
“id”: “123”,
“name”: “皮皮虾”,
“price”: 6.6,
“description”: “看起来很好吃”,
“icon”: “a.jpg”
}
],
“name”: null,
“type”: null
}
]
}

找到了错误的原因,在ResultVo里的foods没有加@JsonProperty注解,而另外两个成员变量上加了,就导致输出的json格式顺序不一样了。
public class ProductVo {

@JsonProperty("name")
private String categoryName;

@JsonProperty("type")
private Integer categoryType;

// @JsonProperty(“foods”)
private List foods;

经过测试,在输出json格式的顺序是以成员变量的先后顺序加载的。

猜你喜欢

转载自blog.csdn.net/qq_41346335/article/details/82831324