首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Json数据中搜索特定格式的数据

在Json数据中搜索特定格式的数据
EN

Stack Overflow用户
提问于 2019-06-02 23:50:13
回答 1查看 55关注 0票数 -1

我有Json数据需要在文本中查找数字文本的长度应该是12,并与2或3个空格,即"text"”:"66 66 6666 6666"

代码语言:javascript
复制
            Response:

            {
              "status": "Succeeded",
              "recognitionResults": [
                {
                  "page": 1,
                  "clockwiseOrientation": 359.9,
                  "width": 8.2633,
                  "height": 11.6933,
                  "unit": "inch",
                  "lines": [
                    {
                      "boundingBox": [
                        1.4525,
                        3.6798,
                        6.8108,
                        3.7013,
                        6.8,
                        4.9709,
                        1.4418,
                        4.9494
                      ],
                      "text": "NOTICE",
                      "words": [
                        {
                          "boundingBox": [
                            1.4764,
                            3.7075,
                            6.7426,
                            3.7227,
                            6.7677,
                            4.9717,
                            1.4605,
                            4.9441
                          ],
                          "text": "NOTICE"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        1.388,
                        5.2614,
                        6.8538,
                        5.2829,
                        6.8538,
                        6.0469,
                        1.3772,
                        6.0253
                      ],
                      "text": "THANK YOU",
                      "words": [
                        {
                          "boundingBox": [
                            1.5363,
                            5.2929,
                            4.4478,
                            5.3025,
                            4.4509,
                            6.0495,
                            1.5363,
                            6.0444
                          ],
                          "text": "THANK"
                        },
                        {
                          "boundingBox": [
                            5.1387,
                            5.3008,
                            6.8166,
                            5.2894,
                            6.8221,
                            6.0663,
                            5.1425,
                            6.0533
                          ],
                          "text": "YOU"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        0.9791,
                        6.2298,
                        7.2519,
                        6.219,
                        7.2519,
                        6.9399,
                        0.9791,
                        6.9507
                      ],
                      "text": "FOR NOTICING",
                      "words": [
                        {
                          "boundingBox": [
                            0.9883,
                            6.2347,
                            2.6539,
                            6.2324,
                            2.6546,
                            6.9685,
                            0.9907,
                            6.9607
                          ],
                          "text": "FOR"
                        },
                        {
                          "boundingBox": [
                            3.2249,
                            6.2323,
                            7.2221,
                            6.2392,
                            7.2182,
                            6.9594,
                            3.225,
                            6.9698
                          ],
                          "text": "NOTICING"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        1.3127,
                        7.1336,
                        6.9507,
                        7.1228,
                        6.9614,
                        7.8867,
                        1.3127,
                        7.8975
                      ],
                      "text": "THIS NOTICE",
                      "words": [
                        {
                          "boundingBox": [
                            1.4169,
                            7.137,
                            3.3154,
                            7.1449,
                            3.3228,
                            7.9057,
                            1.4302,
                            7.9181
                          ],
                          "text": "THIS"
                        },
                        {
                          "boundingBox": [
                            3.8286,
                            7.1459,
                            6.9587,
                            7.1432,
                            6.9545,
                            7.904,
                            3.8343,
                            7.9039
                          ],
                          "text": "NOTICE"
                        }
                      ]
                    }
                  ]
                },
                {
                  "page": 2,
                  "clockwiseOrientation": 359.91,
                  "width": 8.2633,
                  "height": 11.6933,
                  "unit": "inch",
                  "lines": [
                    {
                      "boundingBox": [
                        0.2475,
                        4.0671,
                        3.5614,
                        4.0671,
                        3.5614,
                        4.4222,
                        0.2582,
                        4.4329
                      ],
                      "text": "INCOME TAX DEPARTMENT",
                      "words": [
                        {
                          "boundingBox": [
                            0.297,
                            4.0926,
                            1.3336,
                            4.0875,
                            1.321,
                            4.4334,
                            0.2857,
                            4.4362
                          ],
                          "text": "INCOME"
                        },
                        {
                          "boundingBox": [
                            1.4012,
                            4.0871,
                            1.8519,
                            4.0848,
                            1.8386,
                            4.4338,
                            1.3885,
                            4.4334
                          ],
                          "text": "TAX"
                        },
                        {
                          "boundingBox": [
                            1.9195,
                            4.0845,
                            3.5646,
                            4.0755,
                            3.549,
                            4.443,
                            1.9061,
                            4.4339
                          ],
                          "text": "DEPARTMENT"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        5.2722,
                        4.0671,
                        8.0051,
                        4.0779,
                        7.9943,
                        4.4437,
                        5.2614,
                        4.4329
                      ],
                      "text": "GOVT OF COUNTRY",
                      "words": [
                        {
                          "boundingBox": [
                            5.3301,
                            4.0806,
                            6.3769,
                            4.0887,
                            6.3699,
                            4.436,
                            5.3294,
                            4.4424
                          ],
                          "text": "GOVT"
                        },
                        {
                          "boundingBox": [
                            6.4482,
                            4.089,
                            6.9241,
                            4.0902,
                            6.9138,
                            4.4381,
                            6.4408,
                            4.4361
                          ],
                          "text": "OF"
                        },
                        {
                          "boundingBox": [
                            6.9954,
                            4.0903,
                            8.0184,
                            4.0877,
                            8.0016,
                            4.4531,
                            6.9847,
                            4.4386
                          ],
                          "text": "COUNTRY"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        0.3228,
                        4.831,
                        1.969,
                        4.8526,
                        1.9582,
                        5.1431,
                        0.312,
                        5.1215
                      ],
                      "text": "Your Name",
                      "words": [
                        {
                          "boundingBox": [
                            0.4059,
                            4.8378,
                            1.0645,
                            4.8605,
                            1.0619,
                            5.1452,
                            0.4045,
                            5.132
                          ],
                          "text": "Your"
                        },
                        {
                          "boundingBox": [
                            1.1226,
                            4.8621,
                            1.9754,
                            4.8664,
                            1.9711,
                            5.1487,
                            1.1199,
                            5.1462
                          ],
                          "text": "Name"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        0.4734,
                        6.3266,
                        1.9367,
                        6.3051,
                        1.9475,
                        6.6171,
                        0.4842,
                        6.6494
                      ],
                      "text": "21/03/2009",
                      "words": [
                        {
                          "boundingBox": [
                            0.5434,
                            6.3399,
                            1.9292,
                            6.337,
                            1.9406,
                            6.6308,
                            0.5364,
                            6.6553
                          ],
                          "text": "21/03/2009"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        0.4734,
                        6.714,
                        3.4431,
                        6.7247,
                        3.4323,
                        7.0045,
                        0.4734,
                        7.0045
                      ],
                      "text": "Permanent Account Number",
                      "words": [
                        {
                          "boundingBox": [
                            0.5604,
                            6.733,
                            1.6638,
                            6.7514,
                            1.6633,
                            7.0056,
                            0.5572,
                            7.0154
                          ],
                          "text": "Permanent",
                          "confidence": "Low"
                        },
                        {
                          "boundingBox": [
                            1.72,
                            6.7519,
                            2.5617,
                            6.7517,
                            2.5634,
                            7.007,
                            1.7196,
                            7.0054
                          ],
                          "text": "Account"
                        },
                        {
                          "boundingBox": [
                            2.6178,
                            6.7513,
                            3.4408,
                            6.7391,
                            3.4446,
                            7.0168,
                            2.6197,
                            7.0075
                          ],
                          "text": "Number",
                          "confidence": "Low"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        0.4734,
                        7.2519,
                        2.0981,
                        7.2412,
                        2.1089,
                        7.5209,
                        0.4842,
                        7.5317
                      ],
                      "text": "ABCD1234A",
                      "words": [
                        {
                          "boundingBox": [
                            0.5431,
                            7.2597,
                            2.0998,
                            7.2563,
                            2.0979,
                            7.5283,
                            0.5455,
                            7.5424
                          ],
                          "text": "ABCD1234A",
                          "confidence": "Low"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        7.7469,
                        8.0589,
                        7.7576,
                        7.069,
                        8.0051,
                        7.0798,
                        7.9943,
                        8.0697
                      ],
                      "text": "48042009",
                      "words": [
                        {
                          "boundingBox": [
                            7.7708,
                            7.976,
                            7.7715,
                            7.0862,
                            7.9986,
                            7.085,
                            8.0052,
                            7.9815
                          ],
                          "text": "48042009",
                          "confidence": "Low"
                        }
                      ]
                    }
                  ]
                },
                {
                  "page": 3,
                  "clockwiseOrientation": 359.75,
                  "width": 8.2633,
                  "height": 11.6933,
                  "unit": "inch",
                  "lines": [
                    {
                      "boundingBox": [
                        3.7013,
                        3.5399,
                        6.219,
                        3.5291,
                        6.2298,
                        3.7981,
                        3.712,
                        3.8089
                      ],
                      "text": "GOVERNMENT OF COUNTRY",
                      "words": [
                        {
                          "boundingBox": [
                            3.7553,
                            3.5567,
                            5.245,
                            3.5415,
                            5.2491,
                            3.8153,
                            3.7564,
                            3.813
                          ],
                          "text": "GOVERNMENT"
                        },
                        {
                          "boundingBox": [
                            5.2952,
                            3.5415,
                            5.5797,
                            3.5413,
                            5.5845,
                            3.8136,
                            5.2994,
                            3.8151
                          ],
                          "text": "OF"
                        },
                        {
                          "boundingBox": [
                            5.63,
                            3.5414,
                            6.2158,
                            3.5441,
                            6.2219,
                            3.8083,
                            5.6349,
                            3.8133
                          ],
                          "text": "COUNTRY"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        3.4538,
                        5.1969,
                        7.0367,
                        5.2076,
                        7.026,
                        5.5196,
                        3.4431,
                        5.5089
                      ],
                      "text": "TH faPet/ DOB: 27/07/1982",
                      "words": [
                        {
                          "boundingBox": [
                            3.6995,
                            5.2092,
                            3.9983,
                            5.2089,
                            3.9936,
                            5.5184,
                            3.6952,
                            5.5156
                          ],
                          "text": "TH",
                          "confidence": "Low"
                        },
                        {
                          "boundingBox": [
                            4.058,
                            5.209,
                            4.6953,
                            5.2101,
                            4.6898,
                            5.5228,
                            4.0533,
                            5.5188
                          ],
                          "text": "faPet/",
                          "confidence": "Low"
                        },
                        {
                          "boundingBox": [
                            4.755,
                            5.2103,
                            5.4719,
                            5.2137,
                            5.4656,
                            5.5252,
                            4.7495,
                            5.5231
                          ],
                          "text": "DOB:"
                        },
                        {
                          "boundingBox": [
                            5.5317,
                            5.214,
                            7.0451,
                            5.2289,
                            7.0369,
                            5.5208,
                            5.5252,
                            5.5252
                          ],
                          "text": "27/07/1982"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        3.4431,
                        5.7241,
                        5.1215,
                        5.7026,
                        5.1323,
                        5.9823,
                        3.4538,
                        5.9931
                      ],
                      "text": "you / MALE",
                      "words": [
                        {
                          "boundingBox": [
                            3.5157,
                            5.7258,
                            4.012,
                            5.7319,
                            4.0156,
                            6.0009,
                            3.5184,
                            6.0048
                          ],
                          "text": "you",
                          "confidence": "Low"
                        },
                        {
                          "boundingBox": [
                            4.1774,
                            5.7323,
                            4.2693,
                            5.7319,
                            4.2734,
                            5.9978,
                            4.1813,
                            5.9991
                          ],
                          "text": "/"
                        },
                        {
                          "boundingBox": [
                            4.3244,
                            5.7316,
                            5.133,
                            5.7162,
                            5.1387,
                            5.9818,
                            4.3286,
                            5.997
                          ],
                          "text": "MALE"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        3.2924,
                        7.7146,
                        5.7564,
                        7.7038,
                        5.7671,
                        7.9836,
                        3.3032,
                        7.9943
                      ],
                      "text": "66 66 6666 6666",
                      "words": [
                        {
                          "boundingBox": [
                            3.352,
                            7.7233,
                            3.7049,
                            7.7271,
                            3.6999,
                            8.0037,
                            3.347,
                            8.0059
                          ],
                          "text": "66"
                        },
                        {
                          "boundingBox": [
                            3.7607,
                            7.7275,
                            4.1322,
                            7.7297,
                            4.127,
                            8.0019,
                            3.7556,
                            8.0034
                          ],
                          "text": "66"
                        },
                        {
                          "boundingBox": [
                            4.2065,
                            7.7299,
                            4.9496,
                            7.7286,
                            4.9441,
                            8.0011,
                            4.2013,
                            8.0017
                          ],
                          "text": "6666"
                        },
                        {
                          "boundingBox": [
                            5.0239,
                            7.7282,
                            5.767,
                            7.7199,
                            5.7611,
                            8.0038,
                            5.0184,
                            8.0012
                          ],
                          "text": "6666"
                        }
                      ]
                    }
                  ]
                }
              ]
            }

由于"text":"66 66 6666 6666"存在于第3页块中,因此最终输出应仅显示此块

代码语言:javascript
复制
                {
                  "page": 3,
                  "clockwiseOrientation": 359.75,
                  "width": 8.2633,
                  "height": 11.6933,
                  "unit": "inch",
                  "lines": [
                    {
                      "boundingBox": [
                        3.7013,
                        3.5399,
                        6.219,
                        3.5291,
                        6.2298,
                        3.7981,
                        3.712,
                        3.8089
                      ],
                      "text": "GOVERNMENT OF COUNTRY",
                      "words": [
                        {
                          "boundingBox": [
                            3.7553,
                            3.5567,
                            5.245,
                            3.5415,
                            5.2491,
                            3.8153,
                            3.7564,
                            3.813
                          ],
                          "text": "GOVERNMENT"
                        },
                        {
                          "boundingBox": [
                            5.2952,
                            3.5415,
                            5.5797,
                            3.5413,
                            5.5845,
                            3.8136,
                            5.2994,
                            3.8151
                          ],
                          "text": "OF"
                        },
                        {
                          "boundingBox": [
                            5.63,
                            3.5414,
                            6.2158,
                            3.5441,
                            6.2219,
                            3.8083,
                            5.6349,
                            3.8133
                          ],
                          "text": "COUNTRY"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        3.4538,
                        5.1969,
                        7.0367,
                        5.2076,
                        7.026,
                        5.5196,
                        3.4431,
                        5.5089
                      ],
                      "text": "TH faPet/ DOB: 27/07/1982",
                      "words": [
                        {
                          "boundingBox": [
                            3.6995,
                            5.2092,
                            3.9983,
                            5.2089,
                            3.9936,
                            5.5184,
                            3.6952,
                            5.5156
                          ],
                          "text": "TH",
                          "confidence": "Low"
                        },
                        {
                          "boundingBox": [
                            4.058,
                            5.209,
                            4.6953,
                            5.2101,
                            4.6898,
                            5.5228,
                            4.0533,
                            5.5188
                          ],
                          "text": "faPet/",
                          "confidence": "Low"
                        },
                        {
                          "boundingBox": [
                            4.755,
                            5.2103,
                            5.4719,
                            5.2137,
                            5.4656,
                            5.5252,
                            4.7495,
                            5.5231
                          ],
                          "text": "DOB:"
                        },
                        {
                          "boundingBox": [
                            5.5317,
                            5.214,
                            7.0451,
                            5.2289,
                            7.0369,
                            5.5208,
                            5.5252,
                            5.5252
                          ],
                          "text": "27/07/1982"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        3.4431,
                        5.7241,
                        5.1215,
                        5.7026,
                        5.1323,
                        5.9823,
                        3.4538,
                        5.9931
                      ],
                      "text": "you / MALE",
                      "words": [
                        {
                          "boundingBox": [
                            3.5157,
                            5.7258,
                            4.012,
                            5.7319,
                            4.0156,
                            6.0009,
                            3.5184,
                            6.0048
                          ],
                          "text": "you",
                          "confidence": "Low"
                        },
                        {
                          "boundingBox": [
                            4.1774,
                            5.7323,
                            4.2693,
                            5.7319,
                            4.2734,
                            5.9978,
                            4.1813,
                            5.9991
                          ],
                          "text": "/"
                        },
                        {
                          "boundingBox": [
                            4.3244,
                            5.7316,
                            5.133,
                            5.7162,
                            5.1387,
                            5.9818,
                            4.3286,
                            5.997
                          ],
                          "text": "MALE"
                        }
                      ]
                    },
                    {
                      "boundingBox": [
                        3.2924,
                        7.7146,
                        5.7564,
                        7.7038,
                        5.7671,
                        7.9836,
                        3.3032,
                        7.9943
                      ],
                      "text": "**66 66 6666 6666**",
                      "words": [
                        {
                          "boundingBox": [
                            3.352,
                            7.7233,
                            3.7049,
                            7.7271,
                            3.6999,
                            8.0037,
                            3.347,
                            8.0059
                          ],
                          "text": "66"
                        },
                        {
                          "boundingBox": [
                            3.7607,
                            7.7275,
                            4.1322,
                            7.7297,
                            4.127,
                            8.0019,
                            3.7556,
                            8.0034
                          ],
                          "text": "66"
                        },
                        {
                          "boundingBox": [
                            4.2065,
                            7.7299,
                            4.9496,
                            7.7286,
                            4.9441,
                            8.0011,
                            4.2013,
                            8.0017
                          ],
                          "text": "6666"
                        },
                        {
                          "boundingBox": [
                            5.0239,
                            7.7282,
                            5.767,
                            7.7199,
                            5.7611,
                            8.0038,
                            5.0184,
                            8.0012
                          ],
                          "text": "6666"
                        }
                      ]
                    }
                  ]
                }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-03 00:47:40

命名空间:

代码语言:javascript
复制
using System;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Linq;

代码:

代码语言:javascript
复制
var jsonText = File.ReadAllText("test.txt");
var json = JObject.Parse(jsonText);

var pages = json.Descendants()
    .OfType<JObject>()
    .Where(o => o.Properties().Any(p => p.Name == "page"));

foreach (var pageObject in pages)
{
    var texts = pageObject.Descendants()
        .OfType<JProperty>()
        .Where(p => p.Name == "text" &&
                    p.Value.Value<string>().Replace(" ", "").Length == 12);

    var page = pageObject.Properties().First(p => p.Name == "page");

    foreach (var text in texts)
    {
        Console.WriteLine(text + " exist in page " + page.Value + " block");
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56416594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档