1

So i am trying parse a json file. I am using 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

Ash
  • 41
  • 6

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
  • 15,427
  • 16
  • 64
  • 91