2014-03-29 83 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