首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >解析json对象的Javascript

解析json对象的Javascript
EN

Stack Overflow用户
提问于 2017-10-26 04:13:37
回答 1查看 53关注 0票数 1

我正在尝试使用javascript解析以下(已验证的) json字符串。我尝试过以下代码,但它似乎不起作用。

代码:

代码语言:javascript
运行
复制
var obj = JSON.parse(data);
alert(obj.Design_Lump_Sum[1]);
alert(obj[1]);

json对象:

代码语言:javascript
运行
复制
     {
    "Capex_Lump_Sum": 
    {
    "Pipework and associated fittings": "86086.9",
    "Cable Trays": "10410.4",
    "New Mechanical Services Switchboard": "23209.28",
    "Decommissioning removal of Redundant Mechanical Plant": "28342.32",
    "Electrical system labelling": "473.2",
    "Handover Documentation": "2957.5",
    "Mechanical system labelling": "946.4",
    "Service and Maintenance during DL": "16196.46",
    "Painting": "9227.4",
    "Submain Cabling": "27471.63",
    "Construction Works": "17464.63",
    "Decommissioning removal of redundant mech electrical plant": "5323.5",
    "Framed AsBuilt Drawings": "591.5",
    "Pre Post Air Balancing": "10883.6",
    "Innotech DDC controls and associated cabling": "23831.54",
    "LSL": "2663.0",
    "Testing and Commissioning": "4519.06",
    "Temporary air conditioning": "87243.88",
    "Supply and installation of Air Handling Units Condensor Units": "194521.85",
    "133.0": "105.0",
    "Ductwork Dampers Louvres": "96018.19",
    "Building certifier": "7038.85",
    "Facility Manager Training": "1183.0",
    "AMS": "5915.0",
    "Pre Post Site Acoustic Testing": "5867.68",
    "Penetrations and Fire Sealing": "3903.9"
    },

    "Design_Lump_Sum": 
    {
    "Electrical Services Design": "6915.82",
    "Mechanical Services Design": "13569.01"
    }, 

    "Opex_Lump_Sum": 
    {"Testing and Commissioning": "1200.0"}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-26 04:24:35

由于它已经是一个有效的JSON,所以不需要解析它。只需移除- var obj = JSON.parse(data);行,并以- obj.Design_Lump_Sum['Electrical Services Design']的形式直接访问对象。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46945751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档