下面是输出的Json数组。我想从这个数组中只检索名称和描述。我希望结果进入HTML页面中的表。 请帮帮我。
(
[columnId] => 258f2200948711e3b4507b78fb18a9a7
[columnName] => To-do
[tasksLimited] =>
[tasks] => Array
(
[0] => stdClass Object
(
[_id] => 5f4d17eeff71cf48f8cf033db78c5755
[name] => test
[description] =>
[color] => yellow
[columnId] => 258f2200948711e3b4507b78fb18a9a7
[totalSecondsSpent] => 0
[totalSecondsEstimate] => 0
)
[1] => stdClass Object
(
[_id] => ed30db48426da335d7b232d2d8c5b4f0
[name] => Write report
[description] =>
[color] => red
[columnId] => 258f2200948711e3b4507b78fb18a9a7
[totalSecondsSpent] => 0
[totalSecondsEstimate] => 0
)
[2] => stdClass Object
(
[_id] => ed30db48426da335d7b232d2d8e51eee
[name] => szxfasdfasdf
[description] =>
[color] => yellow
[columnId] => 258f2200948711e3b4507b78fb18a9a7
[totalSecondsSpent] => 0
[totalSecondsEstimate] => 0
)
)
)
答案 0 :(得分:0)
要在JSON中访问您想要的任何元素,您必须循环使用它。
假设您有一个名为 tasks_details
的对象 var tasks_details = your_array['tasks'],
tasks_no = tasks_details.length;
for (var i = 0; i < tasks_no; i++)
{
$('.your_table').append('<tr><td>' + tasks_details[i].name + '</td>\
<td>' + tasks_details[i].description + '</td></tr>');
}
示例代码与之前一样,现在可以选择如何填写表格。