包含括号作为键值的JSON文件

问题描述

我目前有一个json文件,如下所示:

{
"Inventory": [{
        "id": "1","StockNumber": "1000","Make": "Ford","Model": "F150","Trim": "STX","Year": "2011","Color": "Red","Cylinders": "8","Transmission": "Automatic"
        "Gear_Ratio_(4x4)": "",},{
        "id": "2","StockNumber": "1001","Trim": "Lariat","Year": "2012","Color": "Black","Transmission": "Automatic"
        "Gear_Ratio_(4x4)": "4.56",{
        "id": "3","StockNumber": "1002","Make": "Chevy","Model": "Silverato","Trim": "","Year": "2020",}]

}

我的问题是,我无法获取它们作为Gear_Ratio_(4x4)键的值。

我尝试过:

$.getJSON(dataFile,function (data) {
  $.each(data.Inventory,function (index,value) {

        if (value.StockNumber === $("#productStockNumber option:selected").text()) {

          console.log("The Make is: " + value.Make);
          console.log("4x4 Gear ratio is: " + value.Gear_Ratio_(4x4));
        }
    });
});

这有效: console.log(“ Make is:” + value.Make);

这不起作用: console.log(“ 4x4齿轮比为:” + value.Gear_Ratio_(4x4)); 给出错误: 未捕获到的SyntaxError:无效或意外的令牌

我试图逃脱括号,但这没用:

console.log(“ 4x4齿轮比是:” + value.Gear_Ratio _ \(4x4 \));

更改JSON可能不是一种选择,因为还有其他包含括号的键,例如零件的主体尺寸等等。

对不起,如果我自己错过了解决方案。感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...