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,

我试图弄清楚如何解析下面的JSON并从中获取“文本”:“律师”。我看到它有很多分支。i、 e数组和对象。我想用C#做这件事。以下是JSON:

{
  "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");