从Node .js中的GetALexDataInJSONResult JSON数组中读取一个值

时间:2018-02-26 09:38:24

标签: javascript arrays node.js

从Node .js中的JSON数组中读取值

我的回复

   {
    "GetALexDataInJSONResult": [
        {
            "projectid": 6,
            "FullName": "Four laning of Deoli- Kota Section of NH-12 from Km 165.000 to Junction of NH-76 on  Kota Bypass in the State of Rajasthan on BOT (Toll) project on DBFOT pattern under NHDP Phase-III.",
            "piu": "PIU Kota",
            "NumberofLanes": "4L",
            "NHNo_New": "52",
            "NHNo_Old": "12",
            "Total_Length": 83.04,
            "state_name": "Rajasthan"
        }
}

我需要从以下数组中访问“FullName”值 -

错误

 throw err;
    ^

TypeError: Cannot read property '0' of undefined
    at FullNameIntent.customNode (C:\Users\SKBHATI\Desktop\CodeAlexaProject\AlexaNHAIProject\lambda\custom\index.js:64:60)
    at IncomingMessage.res.on (C:\Users\SKBHATI\Desktop\CodeAlexaProject\AlexaNHAIProject\lambda\custom\index.js:137:11)
    at IncomingMessage.emit (events.js:165:20)
    at endReadableNT (_stream_readable.js:1101:12)
    at process._tickCallback (internal/process/next_tick.js:152:19)

1 个答案:

答案 0 :(得分:1)

var obj =    {
    "GetALexDataInJSONResult": [
        {
            "projectid": 6,
            "FullName": "Four laning of Deoli- Kota Section of NH-12 from Km 165.000 to Junction of NH-76 on  Kota Bypass in the State of Rajasthan on BOT (Toll) project on DBFOT pattern under NHDP Phase-III.",
            "piu": "PIU Kota",
            "NumberofLanes": "4L",
            "NHNo_New": "52",
            "NHNo_Old": "12",
            "Total_Length": 83.04,
            "state_name": "Rajasthan"
        }
     ]
}

var myObj = JSON.parse(obj);
var fullName = myObj["GetALexDataInJSONResult"][0]["FullName"]