2012-05-04 257 views
-2

我得到了這個JSON,但必須知道如何從中提取數據。如何從此JSON中提取數據?

我試圖$data['success'][0]['success']和它的工作

不過,我想是這樣$ getPlayerLimit,並返回1000

Array 
(
    [result] => success 
    [source] => Array 
     (
      [0] => getPlayerLimit 
      [1] => getPlayerCount 
     ) 

    [success] => Array 
     (
      [0] => Array 
       (
        [result] => success 
        [source] => getPlayerLimit 
        [success] => 1000 
       ) 

      [1] => Array 
       (
        [result] => success 
        [source] => getPlayerCount 
        [success] => 0 
       ) 

     ) 

) 
+0

值是什麼不起作用? –

+0

我不知道如何從這個JSON中提取數據。 –

回答

0

該陣列可以遍歷找到getPlayerLimit

foreach($data['success'] as $item) 
    { 
     if($item['source'] == 'getPlayerLimit') 
     { 
      /* 
       $item looks like: 

       Array 
       (
        [result] => success 
        [source] => getPlayerLimit 
        [success] => 1000 
       ) 
      */ 
      echo 'player limit is: ' . $item['success']; 
     } 
    }