我想将json转换为以下列格式从REST API获取json的列表或数据集
)]}'
{
"DASH/er/manifest": {
"kind": "gerritcodereview#project",
"id": "DASH%2Fer%2Fmanifest",
"state": "ACTIVE"
},
"DASH/er/projects/amc": {
"kind": "gerritcodereview#project",
"id": "DASH%2Fer%2Fprojects%2Famc",
"state": "ACTIVE"
},
"DASH/er/projects/dash-config": {
"kind": "gerritcodereview#project",
"id": "DASH%2Fer%2Fprojects%2Fdash-config",
"state": "ACTIVE"
},
"DASH/er/projects/dash-sccm-plugin": {
"kind": "gerritcodereview#project",
"id": "DASH%2Fer%2Fprojects%2Fdash-sccm-plugin",
"state": "ACTIVE"
},
"DASH/er/projects/dash-sdk": {
"kind": "gerritcodereview#project",
"id": "DASH%2Fer%2Fprojects%2Fdash-sdk",
"state": "ACTIVE"
},
"DASH/er/source/dash-client-sdk": {
"kind": "gerritcodereview#project",
"id": "DASH%2Fer%2Fsource%2Fdash-client-sdk",
"state": "ACTIVE"
},
"DASH/er/source/dash-configmgr-plugin": {
"kind": "gerritcodereview#project",
"id": "DASH%2Fer%2Fsource%2Fdash-configmgr-plugin",
"state": "ACTIVE"
},
"DASH/er/source/dash-manifests": {
"kind": "gerritcodereview#project",
"id": "DASH%2Fer%2Fsource%2Fdash-manifests",
"state": "ACTIVE"
}
}
任何人都可以帮我将这个json转换为数据集或列表,谢谢
答案 0 :(得分:0)
确保将JSON.NET作为NuGet包安装到您的应用程序中。
首先创建一个具有匹配属性的模型类,例如Kind,Id和State。
var myList = JsonConvert.DeserializeObject<List<YourClass>>(jsonString);
这应该为您提供JSON字符串的对象列表。
此外,您的JSON格式化方式也很难,因为每次最高级别都是唯一的。如果您可以控制JSON的格式,我会这样做,所以你有一个通用类,所有项目,如下面的例子中的Post:
{
"Post": {
"url": "DASH/er/manifest"
"kind": "gerritcodereview#project",
"id": "DASH%2Fer%2Fmanifest",
"state": "ACTIVE"
},
...
}