2014-03-29 84 views
1

下面是输出的Json数组。我想从这个数组中检索唯一的名称和描述。我希望将结果放入HTML页面的表中。 请帮我一把。如何从JSON数组中检索特定数据?

(
      [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

这不是JSON。你可以在这里找到一个例子(http://json.org/example.html)。 –

+0

然后。你的意思是说它只是一个数组? – user3386765

+0

从哪里得到这个JSON值? – Lepanto

回答

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>'); 
    } 

一个示例代码会像以前的对象,现在保持你的选择如何填写表格。

+0

首先谢谢你。这个“your_array”是什么意思。 – user3386765