Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在html表中显示json数组_Javascript_Html - Fatal编程技术网

Javascript 在html表中显示json数组

Javascript 在html表中显示json数组,javascript,html,Javascript,Html,我试图在HTML中显示一个JSON数组,我得到的响应是 [ { "New upto 3 Yrs": 40.0, "Above 3 yr to 9 yrs": 35.0, "Above 9 yrs upto 12 yrs": 30.0 } ] 这里我得到了未定义的值。(见快照) 如何在HTML中将这种JSON显示为HTML表 这是我的剧本: success: function (data) { if (objMotorUnderwrit

我试图在HTML中显示一个JSON数组,我得到的响应是

[
  {
    "New  upto 3 Yrs": 40.0,
    "Above 3 yr to 9 yrs": 35.0,
    "Above 9 yrs upto 12 yrs": 30.0
  }
]
这里我得到了未定义的值。(见快照) 如何在HTML中将这种JSON显示为HTML表

这是我的剧本:

 success: function (data) {
            if (objMotorUnderwritingList.ddlVehicleType == "TW$") {
               // alert("hi TW$");
                if (data.jsDiscoundGridList != 0) {

                        var eachrow = "<tr>"
                                    + "<td>" + data.jsDiscoundGridList[0]["New upto 3 Yrs"] + "</td>"
                                    + "<td>" + data.jsDiscoundGridList[0]["Above 3 yr to 9 yrs"] + "</td>"
                                    + "<td>" + data.jsDiscoundGridList[0]["Above 9 yrs upto 12 yrs"] + "</td>"
                                    + "</tr>";
                        $('.tbody').html(eachrow);

                    }
                else {
                    ShowAlert("Something Wrong in TW");
                } 
            }}
成功:函数(数据){
if(objMotorUnderwritingList.ddlVehicleType==“TW$”){
//警报(“高TW$”;
if(data.jsdispendGridList!=0){
var eachrow=“”
+“”+data.jsDeffindGridList[0][“最长3年的新版本”]+“”
+“+data.jsDiscountGridList[0][”超过3年到9年”]+“
+“+data.jsDeffindGridList[0][“9年以上12年以下”]+”
+ "";
$('.tbody').html(每个箭头);
}
否则{
ShowAlert(“TW中的某些错误”);
} 
}}

如果您的属性名称中有多余的空格,那么如果您更改该名称,您可以很好地访问这些属性:

您的代码:

let数据={
JSDeffindGridList:[{
“新到3年”:40.0,
“3年以上至9年”:35.0,
“9岁以上至12岁”:30.0
}]
};
console.log(data.jsdiscountgridlist[0][“最长3年的新版本]);//未定义

//^
看起来像是额外的
空格
(在键中)对我来说,像这样奇怪的键,我宁愿使用Object.keys并根据每个键进行阅读。是的,好主意!thanx对于解决方案,我尝试了这个方法,但没有在HtML表中获得值,我需要将这个值绑定到HtML表中