我正在尝试解析以下格式的json,是否有任何简单的方法来实现它,而不是递归地解析每个子条目?
{
"Schema": "schema",
"Entities": [{
"Type": "sometype",
"Properties": [{
"Type": "name",
"Value": ["someone"]
}, {
"Type": "date",
"Value": ["sometime"]
}, {
"Type": "description",
"Value": ["this is the description"]
}
}]
}
是否可以将信息提取为
string name = parsedJsonObject["name"]
谢谢
答案 0 :(得分:1)
解析字符串的最快方法是为此JSON创建自定义类,并使用Newtonsoft.JSON。
我想这堂课:
class MyClassForJson
{
public string Schema { get; set; }
public IEnumerable<MyInnerClassForJson> Entities { get; set; }
}
class MyInnerClassForJson
{
public string Type { get; set; }
public IEnumerable<MyInnerInnerClassForJson> Properties { get; set; }
}
class MyInnerInnerClassForJson
{
public string Type { get; set; }
public IEnumerable<string> Value { get; set; }
}
然后您像这样解析它:
using Newtonsoft.Json;
...
var myClassObj = JsonConvert.DeserializeObject<MyClassForJson>(jsonString);