C# 无id的Json净$ref
我想使用$ref来指向对象中的属性,而不是id 具体来说,在下面的示例中,我希望AlternateAddress指向Address1中的city属性C# 无id的Json净$ref,c#,json,json.net,C#,Json,Json.net,我想使用$ref来指向对象中的属性,而不是id 具体来说,在下面的示例中,我希望AlternateAddress指向Address1中的city属性 你能分享一下吗?在Json.NET中没有类似的功能“$ref”对象只能引用以前出现在JSON中的带标签的对象。您希望得到什么最终结果? String str3 = "{ 'Name': 'Jon Smith', 'Address1': { '$id': '1', 'City': 'New York', 'State': 'NY'},
你能分享一下吗?在Json.NET中没有类似的功能
“$ref”
对象只能引用以前出现在JSON中的带标签的对象。您希望得到什么最终结果?
String str3 = "{
'Name': 'Jon Smith',
'Address1': { '$id': '1', 'City': 'New York', 'State': 'NY'},
'AlternateAddress':{'$ref':'#/Address1/City'}}";
Person stuff = JsonConvert.DeserializeObject<Person>(str3, settings);
Console.WriteLine(stuff.AlternateAddress);
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path 'AlternateAddress', line 1, position 105.
at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)
at Newtonsoft.Json.JsonTextReader.ReadAsString()
at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Rextester.Program.Main(String[] args)