json net在版本4.5中反序列化动态属性

时间:2014-09-10 14:10:35

标签: c# json json.net

我想反序列化一个json字符串,并且有许多带有前缀的动态属性,我想将这些动态属性收集到我的集合中,这是我的情况,我有类型:

public class TestType
{
    [JsonProperty(PropertyName="property1")]
    public String Property1;
    [JsonProperty(PropertyName="property2")]
    public String Property2;
    [JsonProperty(PropertyName="dyamicproperties")]
    public List<String> DyamicProperty  
}

我也得到了json的内容:

{
    "dynamic_property1": "sample 3",
    "dynamic_property2": "sample 4",
     //there maybe many other keys starts with 'dynamic_xxxxxx',maybe not
    "property1": "sample 1",
    "property2": "sample 2"
}

结果应该是

...
var result = JsonConvert.Deserialize<TestType>(jsoncontent)
...
result.DynamicProperty //////["dynamic_property1,dynamic_property2"]

怎么样?
注意:我使用的是json.net 4.5,所以我不能在版本6.0.0中使用JsonExtensionDataAttribute

0 个答案:

没有答案