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

时间:2017-05-25 06:18:28

标签: java json

我有一个很大的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                
                }               
              }             
            }               
          }             
        }               
      }             
    } 

1 个答案:

答案 0 :(得分:0)

你可以使用谷歌的Gson库轻松解析json,它只需通过调用该库的fromJson()和toJson()方法将java对象解析为json和json对象为java,试试https://sites.google.com/site/gson/gson-user-guide

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