C#-解析并读取具有重复键的JSON
我试图弄清楚如何解析下面的JSON并从中获取“文本”:“律师”。我看到它有很多分支。i、 e数组和对象。我想用C#做这件事。以下是JSON:C#-解析并读取具有重复键的JSON,c#,json,parsing,C#,Json,Parsing,我试图弄清楚如何解析下面的JSON并从中获取“文本”:“律师”。我看到它有很多分支。i、 e数组和对象。我想用C#做这件事。以下是JSON: { "status": "Succeeded", "succeeded": true, "failed": false, "finished": true, "recognitionResult": { "lines": [{ "boundingBox": [140, 289, 818, 294, 816, 342,
{
"status": "Succeeded",
"succeeded": true,
"failed": false,
"finished": true,
"recognitionResult": {
"lines": [{
"boundingBox": [140, 289, 818, 294, 816, 342, 138, 340],
"text": "General information Com",
"words": [{
"boundingBox": [106, 290, 363, 291, 363, 343, 106, 343],
"text": "General"
}, {
"boundingBox": [323, 291, 659, 291, 659, 344, 323, 343],
"text": "lawyer"
}, {
"boundingBox": [665, 291, 790, 291, 790, 344, 665, 344],
"text": "Com"
}]
}]
}
}
首先使用Quicktype.io生成本机C#类: 然后,使用Newtonsoft调用Result类的一个实例(我们称之为
Result
)
然后你就可以
result.RecognitionResult.Where(s => !string.IsNullOrEmpty(s.Text) && s.Text == "lawyer");
如果您只是想要第一次出现,请使用Hi Karanvir的
.FirstOrDefault()
可能的重复项-这些不是真正的“重复项”,因为每个部分都有自己的定义值,每个部分都可以包含words
本身具有boundingBox
和text
,但是行也具有属性,也包含words
。
result.RecognitionResult.Where(s => !string.IsNullOrEmpty(s.Text) && s.Text == "lawyer");