现象
java
[
{
"delete": false,
"index": 0,
"list": [
{
"duration": 71000,
"id": 0,
"mediumId": 9231114101362,
"path": "",
"point": 100,
"title": "垃圾"
},
{
"duration": 66000,
"id": 0,
"mediumId": 9231114112346,
"path": "",
"point": 100,
"title": "切糕"
},
{
"$ref": "$[0].list[1]"
},
{
"$ref": "$[0].list[0]"
}
],
"tagId": "23080713857"
}
]
解决方法
在list集合中出现" r e f " : " ref": " ref":".list"表示在该list中存在重复引用的情况。为了解决这个问题,可以使用FastJson提供的关闭引用检测的功能。
JSON.toJSONString(list, SerializerFeature.DisableCircularReferenceDetect);
java
List<Object> list = new ArrayList<>();
Object obj1 = new Object();
Object obj2 = new Object();
list.add(obj1);
list.add(obj2);
list.add(list.get(1));
String jsonString = JSON.toJSONString(list, SerializerFeature.DisableCircularReferenceDetect);
System.out.println(jsonString);