我试图反序列化下面的古怪形状的JSON对象成更有道理的类。反序列化古怪形状的JSON对象与Json.NET
{
"item": {
"article_title": {
"type": "text",
"value": "Title of article 1"
},
"content": {
"type": "text",
"value": "Article 1 content"
},
"related_articles": {
"type": "related",
"value": [
"article2"
]
}
},
"additional_items": {
"article2": {
"article_title": {
"type": "text",
"value": "Title of article 2"
},
"content": {
"type": "text",
"value": "Article 2 content"
},
"related_articles": {
"type": "related",
"value": []
}
}
}
}
反序列化为以下Article
类
public class Article {
public string ArticleTitle;
public string Content;
public List<Article> RelatedArticles;
}
的JSON在其根对象两个属性。 Item
是当前项目和additional_items
属性保存在related_articles
属性中引用其他任何物品。
我能够创建基于JsonConverter解决方案有效的解决方案在这里Parse json with different types value (Newtonsoft.Json)描述,但实际上并不是我所需要的。我有很多类似于这个的JSON响应,我不想为它们每个编写一个Converter。我需要的是能够根据属性名称解析值的东西(例如:对于<class-name>.<property-name>
查找item/<property-name>/value
中的值)
您可能需要自定义转换。 – user3682091
http://json2csharp.com –