Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if JSON data duplicates $ref

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report