Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.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/2/jquery/79.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 jquery json显示未定义的html表解析_Javascript_Jquery_Json - Fatal编程技术网

Javascript jquery json显示未定义的html表解析

Javascript jquery json显示未定义的html表解析,javascript,jquery,json,Javascript,Jquery,Json,我想在下面显示html表上的json数据。当我试图用下面的代码显示其show mae undefined时,如何向html表显示 [ { "Key": "data", "Value": [ [ { "Key": "created_time", "

我想在下面显示html表上的json数据。当我试图用下面的代码显示其show mae undefined时,如何向html表显示

[
      {
        "Key": "data",
        "Value": [
          [
            {
              "Key": "created_time",
              "Value": "2020-09-27T21:38:10+0000"
            },
            {
              "Key": "message",
              "Value": "My message"
            },
            {
              "Key": "id",
              "Value": "116312453556631_122404992947377"
            }
          ]
      },
      {
        "Key": "paging",
        "Value": [
          {
            "Key": "cursors",
            "Value": [
              {
                "Key": "before",
                "Value": ""
              },
              {
                "Key": "after",
                "Value": ""
              }
            ]
          }
        ]
      }
    ]
                success: function (data) {
                    var items = '';
                    $.each(data, function (i, item) {
                        
                        var rows = "<tr>"
                        + "<td class='prtoducttd'>" + item.ID + "</td>"
                        + "<td class='prtoducttd'>" + item.Message + "</td>"
                        + "</tr>";
                        $('#tblPost tbody').append(rows);
                    });
                  
                }
            
下面是我的代码和它的显示我未定义

[
      {
        "Key": "data",
        "Value": [
          [
            {
              "Key": "created_time",
              "Value": "2020-09-27T21:38:10+0000"
            },
            {
              "Key": "message",
              "Value": "My message"
            },
            {
              "Key": "id",
              "Value": "116312453556631_122404992947377"
            }
          ]
      },
      {
        "Key": "paging",
        "Value": [
          {
            "Key": "cursors",
            "Value": [
              {
                "Key": "before",
                "Value": ""
              },
              {
                "Key": "after",
                "Value": ""
              }
            ]
          }
        ]
      }
    ]
                success: function (data) {
                    var items = '';
                    $.each(data, function (i, item) {
                        
                        var rows = "<tr>"
                        + "<td class='prtoducttd'>" + item.ID + "</td>"
                        + "<td class='prtoducttd'>" + item.Message + "</td>"
                        + "</tr>";
                        $('#tblPost tbody').append(rows);
                    });
                  
                }
            

检查
item.Key==“数据”
。如果是,则循环通过
item.Value
获取该行的值

var数据=[{
“密钥”:“数据”,
“价值”:[{
“密钥”:“创建时间”,
“值”:“2020-09-27T21:38:10+0000”
},
{
“密钥”:“消息”,
“值”:“我的消息”
},
{
“密钥”:“id”,
“值”:“1163124556631_122404992947377”
}
]
},
{
“键”:“分页”,
“价值”:[{
“键”:“游标”,
“价值”:[{
“键”:“之前”,
“值”:”
},
{
“键”:“之后”,
“值”:”
}
]
}]
}
];
$。每个(数据、功能(i、项){
如果(item.Key==“数据”){
让id,消息,创建;
$.each(item.Value,function(j,obj){
开关(obj.键){
案件编号:
id=对象值;
打破
案例“信息”:
消息=对象值;
打破
案例“创建时间”:
创建=目标价值;
打破
}
});
调试器;
let rows=“”+
“”+id+“”+
“”+消息+“”+
“”+已创建+“”+
"";
$('#tblPost tbody')。追加(行);
}
});

身份证件
消息
创造时间

首先确保正确获取数据

例如,在项目[0]处,查看范围链是否显示对象可用。使用调试器和控制台查看数据结构以遵循作用域链。然后在正确获得项目和i后编写一个循环。

$。每个(数据、函数(i、项目){
$.each(data, function (i, item) {
                    for (i = 0; i < item.Value.length; i++) {

                        
                        let rows = "<tr>" +
                            "<td class='prtoducttd'>" + item.Value[i][2].Value + "</td>" +
                            "<td class='prtoducttd'>" + item.Value[i][1].Value + "</td>" +
                            "<td class='prtoducttd'>" + formatDate(new Date(item.Value[i][0].Value)) + "</td>" +
                            "</tr>";
                        $('#tblPost tbody').append(rows);

                    }
                });
对于(i=0;i
JSON中没有
ID
Message
属性。您希望将什么放入表中?您的JSON是分层的。如何在一个简单的表格中显示这一点并不明显。@Barmar我刚刚编辑了我的问题并添加了预期输出,我添加了一个可执行的代码段。JSON中有一些不匹配的括号,我必须修复它们才能运行它。