[英]deserializing dynamic JSON response
我正在使用Newtonsoft Json.NET API来解析JSON响应。
我有以下JSON:
{
"country" : "DE",
"external_urls":
{
"spotify" : "https://open.spotify.com/user/123",
"another" : "https://open.spotify.com/user/1232"
}
}
两个键“spotify”和“另一个”是动态的,这意味着他们的名字可能随着下一个响应而改变。 也没有固定的长度,“external_urls”中总会有更多或更少的条目
试图将其解析为以下对象:
public class FullProfileResponse
{
[JsonProperty("country")]
public String Country { get; set; }
[JsonProperty("external_urls")]
public ExternalUrls ExternalUrls { get; set; }
}
public class ExternalUrls
{
public String Key { get; set; }
public String Value { get; set; }
}
如何让Json.NET将Key-Name反序列化为public String Key
? 所以我会有Key = "spotify"
和Key = "another"
我需要使用List或IEnumerable,但如果它是一个总是可以改变其大小而不是数组的动态对象呢?
将ExternalUrls声明为
[JsonProperty("external_urls")]
public Dictionary<string,string> ExternalUrls { get; set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.