Json.NET可以反序列化为IEnumerable <keyvaluepair <string,string>&gt;?

时间:2017-09-01 12:51:56

标签: json.net

Json.NET可以反序列化吗?

public class C
{
    [JsonConstructor]
    public C(IEnumerable<KeyValuePair<string,string>> values)
    ...
}

1 个答案:

答案 0 :(得分:0)

只需反序列化为Dictionary<string, string>并在其上调用ToList()

var myJson = @"{""key1"": ""value1"", ""key2"": ""value2""}";

IEnumerable<KeyValuePair<string, string>> myEnumerable;

myEnumerable = JsonConvert.DeserializeObject<Dictionary<string, string>>(myJson).ToList();