1

So I am trying to parse a JSON file. I am using an alert to get the value of a particular field, but whenever I pass this particular string it is displayed as NaN:

myjsondata=JSON.parse(json);
alert(myjsondata.result.parameters.College-name);

Json file

`{
  "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"
}` 

Alert with action and other fields are working fine. But for college it is displayed as NAN.

Ahmad Adibzad
  • 501
  • 2
  • 6
  • 14
Ash
  • 41
  • 7

1 Answers1

3

You are getting a null value because parameters does not have a key called College-name:

"parameters": {},

Also, you might want to change your selection be using:

alert(myjsondata.result.parameters['College-name']);
Koby Douek
  • 16,156
  • 19
  • 74
  • 103