gpt4 book ai didi

javascript - Json解析javascript : String displayed as NAN

转载 作者:行者123 更新时间:2023-12-01 03:40:34 26 4
gpt4 key购买 nike

所以我正在尝试解析一个 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 没有名为 College-name 的键:

"parameters": {},

此外,您可能希望使用以下方法更改您的选择:

alert(myjsondata.result.parameters['College-name']);

关于javascript - Json解析javascript : String displayed as NAN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43906452/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com