說,我有一些JSON這樣的:Json.Net反序列化提領
[{"$id": 1, Prop1: true, Prop2: {"$id": 2, Prop2: {"$id": 3, SomeProp: true}}}, {"$ref" : 3}]
而且我用JsonConvert.DeserializeObject(aboveJson)。我如何才能確保其反序列化到這一點:
[{Prop1: true}, {SomeProp: true}] //[0] = id1, [1] = id3
取而代之的是:
[{Prop1: true}, null] //[0] = id1, [1] = null because it doesn't match on "$ref" down the hierarchy.
編輯的清晰度: 爲什麼當我運行這段代碼
public class StackOverflow
{
public bool Prop1 { get; set; }
}
static void Main(string[] args)
{
string json = @"[{""$id"": ""1"", Prop1: true, Prop2: {""$id"": ""2"", Prop2: {""$id"": ""3"", Prop1: true}}}, {""$ref"" : ""3""}]";
dynamic result = JsonConvert.DeserializeObject<List<StackOverflow>>(json);
}
結果[0]是一個StackOverflow類。結果[1]爲空。我如何得到它的解除引用?我錯過了什麼?
找到答案這裏: http://stackoverflow.com/questions/23505381/json-tree-modifications-that-dont-break-ref-references – MaitlandMarshall
你手型的JSON?因爲Json.NET需要'「$ ref」'和'「$ id」'值爲字符串,而不是整數。 – dbc
對不起,這只是僞代碼。 – MaitlandMarshall