我试图使用IBM沃森的通话API使用此代码来获得结果:我怎样才能获得JSON的价值在Python
import json
from watson_developer_cloud import ConversationV1
conversation = ConversationV1(
username='******',
password='*****',
version='2016-09-20')
workspace_id = '***'
response = conversation.message(workspace_id=workspace_id, message_input={
'text': 'hi'})
print(json.dumps(response, indent=2))
运行这段代码将打印此JSON:
{
"intents": [
{
"confidence": 1,
"intent": "greating"
}
],
"entities": [],
"context": {
"conversation_id": "d6952ab6-e27e-4c50-8b90-01f3087bcc0e",
"system": {
"dialog_stack": [
{
"dialog_node": "root"
}
],
"dialog_request_counter": 1,
"dialog_turn_counter": 1,
"branch_exited": true,
"_node_output_map": {
"greeting": [
0
]
},
"branch_exited_reason": "completed"
}
},
"input": {
"text": "hi"
},
"output": {
"log_messages": [],
"nodes_visited": [
"greeting"
],
"text": [
"Hi I am Nao Nice to meet you"
]
},
"alternate_intents": false
}
我试过很多方法,但无法解码这个JSON。我只想得到输出文字:“你好,我很好,很高兴见到你。”我怎样才能做到这一点?
很好<3我的方法是尝试解码json.dump数据,所以我不能得到任何东西<3很多谢谢你 –