繁体   English   中英

如何从大JSON文档中提取数据?

[英]How do I extract data from a big JSON document?

我有一个很大的JSON字符串,我不知道从下面的JSON字符串中提取信息。 我需要获取links属性,但是我有字符串行“ 0”和“ 1”,所以有没有获取所有链接的想法?

    "dictationResult": {                
      "status": "TRANSCRIBED",              
      "reference": "96b69340-e15b-11e6-b15f-ebe483888f20",              
      "sequence": 1,                
      "operating_mode": "accurate",             
      "channels": {             
        "caller_audio": {               
          "errors": [ ],                
          "lattice": {              
            "1": {              
              "links": {                
                "0": {              
                  "start": 0,               
                  "end": 0.44,              
                  "weight": 0,              
                  "word_confidence": 0.974111,              
                  "best_path": true,                
                  "word": "!ENTER",             
                  "intensity": 0                
                },              
                "1": {              
                  "start": 0.44,                
                  "end": 0.62,              
                  "weight": -0.153224,              
                  "word_confidence": 0.674667,              
                  "best_path": true,                
                  "word": "my",             
                  "intensity": 0                
                },              
                "2": {              
                  "start": 0.44,                
                  "end": 0.62,              
                  "weight": -1.983807,              
                  "best_path": false,               
                  "word": "!NULL",              
                  "intensity": 0                
                },              
                "3": {              
                  "start": 0.44,                
                  "end": 0.62,              
                  "weight": -6.090047,              
                  "best_path": false,               
                  "word": "!PAUSE-FILLER",              
                  "intensity": 0                
                },              
                "4": {              
                  "start": 0.44,                
                  "end": 0.62,              
                  "weight": -6.095767,              
                  "best_path": false,               
                  "word": "I've",               
                  "intensity": 0                
                },              
                "5": {              
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -0.903016,              
                  "best_path": true,                
                  "word": "!NULL",              
                  "intensity": 0                
                },              
                "6": {              
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -1.021551,              
                  "best_path": false,               
                  "word": "heart",              
                  "intensity": 0                
                },              
                "7": {              
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -1.593481,              
                  "best_path": false,               
                  "word": "God",                
                  "intensity": 0                
                },              
                "8": {              
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -4.525031,              
                  "best_path": false,               
                  "word": "mother",             
                  "intensity": 0                
                },              
                "9": {              
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -4.587421,              
                  "best_path": false,               
                  "word": "partner",                
                  "intensity": 0                
                },              
                "10": {             
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -4.901502,              
                  "best_path": false,               
                  "word": "daughter",               
                  "intensity": 0                
                },              
                "11": {             
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -5.825034,              
                  "best_path": false,               
                  "word": "wife",               
                  "intensity": 0                
                },              
                "12": {             
                  "start": 0.94,                
                  "end": 1.04,              
                  "weight": -0.764942,              
                  "word_confidence": 0.229834,              
                  "best_path": true,                
                  "word": "!SILENCE",               
                  "intensity": 0                
                },              
                "13": {             
                  "start": 0.94,                
                  "end": 1.04,              
                  "weight": -1.179495,              
                  "best_path": false,               
                  "word": "!NULL",              
                  "intensity": 0                
                },              
                "14": {             
                  "start": 0.94,                
                  "end": 1.04,              
                  "weight": -2.148265,              
                  "best_path": false,               
                  "word": "my",             
                  "intensity": 0                
                },              
                "15": {             
                  "start": 0.94,                
                  "end": 1.04,              
                  "weight": -2.294212,              
                  "best_path": false,               
                  "word": "got",                
                  "intensity": 0                
                },              
                "16": {             
                  "start": 0.94,                
                  "end": 1.04,              
                  "weight": -4.637921,              
                  "best_path": false,               
                  "word": "drive",              
                  "intensity": 0                
                },              
                "17": {             
                  "start": 1.04,                
                  "end": 1.1,               
                  "weight": -0.003238,              
                  "best_path": true,                
                  "word": "!NULL",              
                  "intensity": 0                
                },              
                "18": {             
                  "start": 1.04,                
                  "end": 1.1,               
                  "weight": -5.734553,              
                  "best_path": false,               
                  "word": "!SILENCE",               
                  "intensity": 0                
                },              
                "19": {             
                  "start": 1.1,             
                  "end": 1.32,              
                  "weight": 0,              
                  "word_confidence": 0.951371,              
                  "best_path": true,                
                  "word": "my",             
                  "intensity": 0                
                },              
                "20": {             
                  "start": 1.32,                
                  "end": 1.58,              
                  "weight": -0.00059,               
                  "word_confidence": 0.950269,              
                  "best_path": true,                
                  "word": "dog",                
                  "intensity": 0                
                },              
                "21": {             
                  "start": 1.32,                
                  "end": 1.58,              
                  "weight": -7.43585,               
                  "best_path": false,               
                  "word": "dad",                
                  "intensity": 0                
                },              
                "22": {             
                  "start": 1.58,                
                  "end": 1.74,              
                  "weight": -0.039555,              
                  "word_confidence": 0.704629,              
                  "best_path": true,                
                  "word": "was",                
                  "intensity": 0                
                },              
                "23": {             
                  "start": 1.58,                
                  "end": 1.74,              
                  "weight": -3.249785,              
                  "best_path": false,               
                  "word": "were",               
                  "intensity": 0                
                },              
                "24": {             
                  "start": 1.74,                
                  "end": 2.2,               
                  "weight": -0.041701,              
                  "word_confidence": 0.670428,              
                  "best_path": true,                
                  "word": "stolen",             
                  "intensity": 0                
                },              
                "25": {             
                  "start": 1.74,                
                  "end": 2.2,               
                  "weight": -3.252876,              
                  "best_path": false,               
                  "word": "stalling",               
                  "intensity": 0                
                },              
                "26": {             
                  "start": 1.74,                
                  "end": 2.2,               
                  "weight": -6.127987,              
                  "best_path": false,               
                  "word": "told",               
                  "intensity": 0                
                },              
                "27": {             
                  "start": 2.2,             
                  "end": 2.675,             
                  "weight": 0,              
                  "word_confidence": 0.944035,              
                  "best_path": true,                
                  "word": "!EXIT",              
                  "intensity": 0                
                }               
              }             
            }               
          },                
          "partial_lattice": {              
            "1": {              
              "links": {                
                "0": {              
                  "start": 0,               
                  "end": 0.44,              
                  "weight": 0,              
                  "word_confidence": 0.974111,              
                  "best_path": true,                
                  "word": "!ENTER",             
                  "intensity": 0                
                },              
                "1": {              
                  "start": 0.44,                
                  "end": 0.62,              
                  "weight": -0.153224,              
                  "word_confidence": 0.674667,              
                  "best_path": true,                
                  "word": "my",             
                  "intensity": 0                
                },              
                "2": {              
                  "start": 0.44,                
                  "end": 0.62,              
                  "weight": -1.983807,              
                  "best_path": false,               
                  "word": "!NULL",              
                  "intensity": 0                
                },              
                "3": {              
                  "start": 0.44,                
                  "end": 0.62,              
                  "weight": -6.090047,              
                  "best_path": false,               
                  "word": "!PAUSE-FILLER",              
                  "intensity": 0                
                },              
                "4": {              
                  "start": 0.44,                
                  "end": 0.62,              
                  "weight": -6.095767,              
                  "best_path": false,               
                  "word": "I've",               
                  "intensity": 0                
                },              
                "5": {              
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -0.903016,              
                  "best_path": true,                
                  "word": "!NULL",              
                  "intensity": 0                
                },              
                "6": {              
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -1.021551,              
                  "best_path": false,               
                  "word": "heart",              
                  "intensity": 0                
                },              
                "7": {              
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -1.593481,              
                  "best_path": false,               
                  "word": "God",                
                  "intensity": 0                
                },              
                "8": {              
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -4.525031,              
                  "best_path": false,               
                  "word": "mother",             
                  "intensity": 0                
                },              
                "9": {              
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -4.587421,              
                  "best_path": false,               
                  "word": "partner",                
                  "intensity": 0                
                },              
                "10": {             
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -4.901502,              
                  "best_path": false,               
                  "word": "daughter",               
                  "intensity": 0                
                },              
                "11": {             
                  "start": 0.62,                
                  "end": 0.94,              
                  "weight": -5.825034,              
                  "best_path": false,               
                  "word": "wife",               
                  "intensity": 0                
                },              
                "12": {             
                  "start": 0.94,                
                  "end": 1.04,              
                  "weight": -0.764942,              
                  "word_confidence": 0.229834,              
                  "best_path": true,                
                  "word": "!SILENCE",               
                  "intensity": 0                
                },              
                "13": {             
                  "start": 0.94,                
                  "end": 1.04,              
                  "weight": -1.179495,              
                  "best_path": false,               
                  "word": "!NULL",              
                  "intensity": 0                
                },              
                "14": {             
                  "start": 0.94,                
                  "end": 1.04,              
                  "weight": -2.148265,              
                  "best_path": false,               
                  "word": "my",             
                  "intensity": 0                
                },              
                "15": {             
                  "start": 0.94,                
                  "end": 1.04,              
                  "weight": -2.294212,              
                  "best_path": false,               
                  "word": "got",                
                  "intensity": 0                
                },              
                "16": {             
                  "start": 0.94,                
                  "end": 1.04,              
                  "weight": -4.637921,              
                  "best_path": false,               
                  "word": "drive",              
                  "intensity": 0                
                },              
                "17": {             
                  "start": 1.04,                
                  "end": 1.1,               
                  "weight": -0.003238,              
                  "best_path": true,                
                  "word": "!NULL",              
                  "intensity": 0                
                },              
                "18": {             
                  "start": 1.04,                
                  "end": 1.1,               
                  "weight": -5.734553,              
                  "best_path": false,               
                  "word": "!SILENCE",               
                  "intensity": 0                
                },              
                "19": {             
                  "start": 1.1,             
                  "end": 1.32,              
                  "weight": 0,              
                  "word_confidence": 0.951371,              
                  "best_path": true,                
                  "word": "my",             
                  "intensity": 0                
                },              
                "20": {             
                  "start": 1.32,                
                  "end": 1.58,              
                  "weight": -0.00059,               
                  "word_confidence": 0.950269,              
                  "best_path": true,                
                  "word": "dog",                
                  "intensity": 0                
                },              
                "21": {             
                  "start": 1.32,                
                  "end": 1.58,              
                  "weight": -7.43585,               
                  "best_path": false,               
                  "word": "dad",                
                  "intensity": 0                
                },              
                "22": {             
                  "start": 1.58,                
                  "end": 1.74,              
                  "weight": -0.039555,              
                  "word_confidence": 0.704629,              
                  "best_path": true,                
                  "word": "was",                
                  "intensity": 0                
                },              
                "23": {             
                  "start": 1.58,                
                  "end": 1.74,              
                  "weight": -3.249785,              
                  "best_path": false,               
                  "word": "were",               
                  "intensity": 0                
                },              
                "24": {             
                  "start": 1.74,                
                  "end": 2.2,               
                  "weight": -0.041701,              
                  "word_confidence": 0.670428,              
                  "best_path": true,                
                  "word": "stolen",             
                  "intensity": 0                
                },              
                "25": {             
                  "start": 1.74,                
                  "end": 2.2,               
                  "weight": -3.252876,              
                  "best_path": false,               
                  "word": "stalling",               
                  "intensity": 0                
                },              
                "26": {             
                  "start": 1.74,                
                  "end": 2.2,               
                  "weight": -6.127987,              
                  "best_path": false,               
                  "word": "told",               
                  "intensity": 0                
                },              
                "27": {             
                  "start": 2.2,             
                  "end": 2.675,             
                  "weight": 0,              
                  "word_confidence": 0.944035,              
                  "best_path": true,                
                  "word": "!EXIT",              
                  "intensity": 0                
                }               
              }             
            }               
          }             
        }               
      }             
    } 

你可以简单地通过调用fromJson()和的toJSON()该库的方法尝试很容易使用谷歌的GSON库解析JSON,它将解析Java对象的JSON和JSON对象到Java https://sites.google.com/site / GSON / GSON用户导

    Gson gson = new Gson();

// 1. JSON to Java object, read it from a file.
Staff staff = gson.fromJson(new FileReader("D:\\file.json"), Staff.class);

// 2. JSON to Java object, read it from a Json String.
String jsonInString = "{'name' : 'pravin'}";
Staff staff = gson.fromJson(jsonInString, Staff.class);

// JSON to JsonElement, convert to String later.
JsonElement json = gson.fromJson(new FileReader("D:\\file.json"), JsonElement.class);
    String result = gson.toJson(json);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM