Using Microsoft WebApi 2 (which uses the third party Json.NET library), let's say I return the following people
array:
var p1 = new Person("Alice");
var p2 = new Person("Bob");
p1.Sibling = p2;
p2.Sibling = p1;
var people = new[] { p1, p2 };
To avoid circular references, it Json.NET outputs the following JSON:
[
{
"$id":"1",
"Name":"Alice",
"Sibling":{
"$id":"2",
"Name":"Bob",
"Sibling":{
"$ref":"1"
}
}
},
{
"$ref":"2"
}
]
Javascript's JSON.parse() method doesn't know anything about this syntax. I looked up the JSON spec, and I see uses of the $ref keyword in pointers, but I don't see them using the $id keyword. Is this something quirky about Json.NET? Or is it something in the JSON spec that just isn't widely supported?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…