What if JSON data duplicates $ref
This article focuses on "what to do when JSON data repeats $ref". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what to do when JSON data repeats $ref"!
Repetition of JSON data $ref
JSONArray type if we add the data inside, if the data is the same, then it will be replaced with $ref: that is, it will be simplified because the data points directly to the previous data.
Circular reference: when an object contains another object, fastjson parses the object into a reference. References are marked through $ref. Here are some descriptions of references
"$ref": ".." One level up
"$ref": "@" current object, that is, self-reference
"$ref": "$" root object
"$ref": "$.children.0" is a path-based reference, equivalent to root.getChildren (). Get (0)
For example, the following three bank cards are all owned by CCB, then this problem will occur because the bank information is exactly the same.
Because we are going to display the data at the front end, so this is definitely wrong, so what if we solve the problem?
It is said on the Internet that SerializerFeature.DisableCircularReferenceDetect is added.
1 first convert JSONArray to string and add SerializerFeature.DisableCircularReferenceDetect at this time
JSONArray.toJSONString (userBankJsonArray, SerializerFeature.DisableCircularReferenceDetect)
2 because it used to be in JSON format, we have to convert string to JSON.
JSONObject.parse (JSONArray.toJSONString (userBankJsonArray, SerializerFeature.DisableCircularReferenceDetect))
Then it will be no problem when it is passed to the front end for analysis.
At this point, I believe you have a deeper understanding of "JSON data repeat $ref". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!