![](/img/trans.png)
[英]Does C# have any built in objects for turning JSON text into manageable objects or do I need a third party library?
[英]Is there any library that converts C# objects with references into dojox.json.ref compatible JSON?
我想將一些帶有循環引用的.NET對象序列化為兼容的JSON,並且可以使用Dojo庫dojox.json.ref
進行解析和解析。 該庫允許序列化以下內容:
var obj = {};
obj.me = obj;
像這樣:
var jsonWithCircularRef = dojox.json.ref.toJson(obj);
obj = dojox.json.ref.fromJson(jsonWithCircularRef);
obj.me == obj // -> true, the reproduced object will
//have a property named "me" with a value of itself.
JSON(具有完整引用)如下所示:
{"id":"1","me":{"$ref":"1"}}
我想要的是代碼或庫,使我可以在服務器端使用C#將具有循環引用的對象轉換為可以由dojox.json.ref
庫解析的JSON(具有完整的引用,如上所述)。 已經有東西了嗎?
JSON.Net(http://json.codeplex.com/)庫可以使用保留的引用序列化對象圖。 結果JSON的語法與您的示例幾乎相同,唯一的區別是'id'是'$ id'。 我不知道Dojo是否可以解決這個問題。 如果不是,則JSON.Net庫是開源的,因此您可以為Dojo兼容語法添加一個選項。
JSON.Net庫也有很好的文檔。 這是有關保留引用的頁面: http : //james.newtonking.com/projects/json/help/PreserveObjectReferences.html 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.