2016-01-06 115 views
-1
{ 
"status_code": 0, 
"result_type": "DRAGON_NLU_ASR_CMD", 
"NMAS_PRFX_SESSION_ID": "8c63c3ed-40da-4cdc-8ad8-1dd94ce8e466", 
"NMAS_PRFX_TRANSACTION_ID": "1", 
"audio_transfer_info": { 
    "packages": [ 
     { 
      "time": "20160105015723190", 
      "bytes": 1668 
     }, 
     { 
      "time": "20160105015723646", 
      "bytes": 7613 
     } 
    ], 
    "nss_server": "10.56.11.186:4510", 
    "end_time": "20160105015723645", 
    "audio_id": 1, 
    "start_time": "20160105015722835" 
}, 
"cadence_regulatable_result": "completeRecognition", 
"appserver_results": { 
    "status": "success", 
    "final_response": 1, 
    "payload": { 
     "diagnostic_info": { 
      "adk_dialog_manager_status": "undefined", 
      "nlu_version": "[NLU_PROJECT:NVCCP-deu-DEU];[Datapack:Version: nlps-deu-DEU-NVCCP-6.1.100.12-2-GMT20151130161021];[VL-Models:Version: vlmodels-NVCCP-deu-DEU-6.1.100.12-2-GMT20151130160231]", 
      "nlps_host": "mt-dmz-nlps002.nuance.com:8636", 
      "nlps_ip": "10.56.10.51", 
      "application": "AUDI_2017", 
      "nlu_component_flow": "[Input:VoiceJSON] [FieldID|auto_main] [NLUlib|C-eckart-r$Rev$.f20151118.1250] [build|G-r72490M.f20151130.1055] [vlmodel|Version: vlmodels-NVCCP-deu-DEU-6.1.100.12-2-GMT20151130160231] [Flow|+VlingoTokenized]", 
      "third_party_delay": "0", 
      "nmaid": "AUDI_SDS_2017_EXT_20151203", 
      "nlps_profile": "AUDI_2017", 
      "fieldId": "auto_main", 
      "nlps_profile_package_version": "r159218", 
      "nlu_annotator": "com.nuance.NVCCP.deu-DEU.ncs51.VlingoNLU-client-qNVCCP_NCS51", 
      "ext_map_time": "3", 
      "nlu_use_literal_annotator": "0", 
      "int_map_time": "1", 
      "nlps_nlu_type": "nlu_project", 
      "nlu_language": "deu-DEU", 
      "timing": { 
       "finalRespSentDelay": "311", 
       "intermediateRespSentDelay": "1896" 
      }, 
      "nlps_profile_package": "AUDI_2017" 
     }, 
     "actions": [ 
      { 
       "Input": { 
        "Interpretations": [ 
         "18 Slash 6/2015" 
        ], 
        "Type": "asr" 
       }, 
       "Instances": [ 
        { 
         "nlu_classification": { 
          "Domain": "UDE", 
          "Intention": "Unspecified" 
         }, 
         "nlu_interpretation_index": 1, 
         "nlu_slot_details": { 
          "Location": { 
           "literal": "18 Slash 6/2015" 
          }, 
          "Search-phrase": { 
           "literal": "18 slash 6/2015" 
          } 
         }, 
         "interpretation_confidence": 3174 
        } 
       ], 
       "type": "nlu_results", 
       "api_version": "1.0" 
      } 
     ], 
     "nlps_version": "nlps(z):6.1.100.12.2-B359;Version: nlps-base-Zeppelin-6.1.100-B124-GMT20151130193521;" 
    } 
}, 
"final_response": 1, 
"prompt": "", 
"result_format": "appserver_post_results" 
} 

我想将上面的JSON转换为Python中的字典数据类型。在上面的脚本中,我想读取这个值 -将JSON字符串转换为python中的字典

{"Domain":"UDE","Intention":"Unspecified"} 

我是json的新手,所以我无法理解。有人可以给我建议一些想法。

+0

那么你尝试?而你不明白的是什么? –

+0

您是否尝试过使用内建的['json'模块](https://docs.python.org/3/library/json.html#json.loads)? –

+0

我试过这个:json.loads(“nlu_classification”)。但它不起作用 – user2306769

回答

0

只需使用python自带的json模块。

import json 
json_string = '{"first_name": "Guido", "last_name":"Rossum"}' 
parsed_json = json.loads(json_string) 
print(parsed_json['first_name']) 
"Guido" 

参考:http://docs.python-guide.org/en/latest/scenarios/json/

+0

你能告诉我如何只读域和意图值吗? – user2306769

+0

非常简单。像任何普通字典一样使用它。 – Rohit