如何解决包含括号作为键值的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 举报,一经查实,本站将立刻删除。