그래서 json 파일을 구문 분석하려고합니다. 특정 필드의 값을 가져 오기 위해 경고를 사용하고 있지만이 특정 문자열을 전달할 때마다 nan으로 표시됩니다.
myjsondata=JSON.parse(json);
alert(myjsondata.result.parameters.College-name);
Json 파일
`{
"id": "1",
"timestamp": "2017-05-11T04:03:26.008Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "hi",
"action": "input.welcome",
"actionIncomplete": false,
"parameters": {
"College-name": "Apex Technical School"},
"contexts": [],
"metadata": {
"intentId": "b11a9493-7c2f-47c0-9928-5653a10c86e9",
"webhookUsed": "false",
"webhookForSlotFillingUsed": "false",
"intentName": "Default Welcome Intent"
},
"fulfillment": {
"speech": "Hi welcome from webfocus Api Ai",
"messages": [
{
"type": 0,
"speech": "Hi welcome from webfocus Api Ai"
},
{
"type": 0,
"speech": ""
}
]
},
"score": 1
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "04737548-a3ff-485d-af1a-304edfee9486"
}`
작업 경고 및 기타 필드가 제대로 작동합니다. 하지만 대학에서는 NAN으로 표시됩니다.
parameters
라는 키가 없기 때문에 null 값이 발생합니다 College-name
.
"parameters": {},
또한 다음을 사용하여 선택 사항을 변경할 수도 있습니다.
alert(myjsondata.result.parameters['College-name']);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다