【发布时间】:2016-03-23 23:31:34
【问题描述】:
我这里有这个 JSON:
{
"id": "-KDYmr0aI0UmjKRyd465",
"name": "No Name",
"presentation": {
"fields": [
{
"defaultValue": "Erste Node",
"id": "test",
"title": "test",
"type": "text"
},
{
"defaultValue": "Zweite node",
"id": "test2",
"title": "test2",
"type": "text"
}
]
},
"thumbnail": "/images/defaultimage.png",
"updated": "2016-03-23T14:05:32+00:00",
"userData": {
"test": "Erste Node",
"test2": "Zweite node"
}
}
userData 的变化取决于用户是否添加了一些数据。所以假设用户添加了一些数据,例如{"test3":"More testdata"},userdata json 看起来像这样:
"userData": {
"test": "Erste Node",
"test2": "Zweite node",
"test3": "More testdata"
}
字段也会相应更新,但我知道如何将这些字段映射到 C# 类。 我的问题是我如何能够将此 userData 序列化为 C# 类 - 而且还可以从这里使用 RestSharp 客户端:http://restsharp.org/
这几乎就是我的课程的样子。但我不知道如何映射 userData...
public class Field
{
public string defaultValue { get; set; }
public string id { get; set; }
public string title { get; set; }
public string type { get; set; }
}
public class Presentation
{
public List<Field> fields { get; set; }
}
public class RootObject
{
public string id { get; set; }
public string name { get; set; }
public Presentation presentation { get; set; }
public string thumbnail { get; set; }
public string updated { get; set; }
public UserData userData { get; set; }
}
【问题讨论】:
标签: c# json serialization restsharp