fastjson JSONArray转String,打印出来不正确

uplii1fm  于 2021-11-27  发布在  Java
关注(0)|答案(1)|浏览(370)
String s = "{\"name\":\"测试\"}";
JSONObject o = JSONObject.parseObject(s);
System.out.println(o);
JSONArray array = new JSONArray();
array.add(o);
array.add(o);
System.out.println(array.toJSONString());
System.out.println(array.toString());

运行结果是:
{"name":"测试"}
[{"name":"测试"},{"$ref":"$[0]"}]
[{"name":"测试"},{"$ref":"$[0]"}]

r9f1avp5

r9f1avp51#

JSON.toJSONString(array, SerializerFeature.DisableCircularReferenceDetect);

相关问题