2014-09-06 66 views
0

我需要只讀取遊覽項目的數據幫助, 我已經在我的網站這個PHP腳本:從JSON到php的數據?

<?php $json_string = 'http://framecreators.nl/efteling/data.php'; $jsondata file_get_content($json_string); $json_o=json_decode(utf8_encode($data)); $attractie = $json_o['Id']['Type']; echo $attractie ?> 

這JSON數據:

http://framecreators.nl/efteling/data.php

我只需要一個識別碼轉換和鍵入,如果有人可以幫助我。

回答

0

要訪問您要查找的數據,你需要做這樣的事情:

foreach ($json_o['AttractionInfo'] as $a) { 
    echo $a['Id']; //or whatever you're planning to do with this data 
    ech0 $a['Type']; 
} 
+0

謝謝,我要去嘗試吧! – 2014-09-06 18:35:47

0
<?php 
$json_data = file_get_contents('http://framecreators.nl/efteling/data.php'); 
$data = json_decode($json_data); 
$array = []; 
foreach($data->AttractionInfo as $item) { 
    $array['id'][] = $item->Id; 
    $array['type'][] = $item->Type; 
} 
echo "<pre>"; 
print_r($array); 
echo "</pre>"; 
0

$ URL = 「http://framecreators.nl/efteling/data.php」;

$ content = file_get_contents($ url);

$ data = json_decode($ content,TRUE);

$ array = $ data ['AttractionInfo'];

foreach($ array as $ r) { echo「ID - >」。$ r ['Id'];

echo'
';

echo「Type - >」。$ r ['Type'];

echo'
';

}

+0

我該如何處理? javascript還是? – 2014-09-06 18:59:38

+0

我得到這個錯誤:爲foreach提供的無效參數() – 2014-09-06 19:03:05

+0

<?php $ url =「http://framecreators.nl/efteling/data.php」; $ content = file_get_contents($ url); $ data = json_decode($ content,TRUE); $ array = $ data ['AttractionInfo']; foreach($ array as $ r) { echo「ID - >」。$ r ['Id']; echo'
'; echo「Type - >」。$ r ['Type']; echo'
'; } ?> – Algobasket 2014-09-06 19:06:50

0

$ URL = 「http://framecreators.nl/efteling/data.php」;

$ content = file_get_contents($ url);

$ data = json_decode($ content,TRUE);

$ array = $ data ['AttractionInfo'];

如果(is_array($陣列)) {

的foreach($數組作爲$ R) { 回波$ R [ 'ID'];

echo $r['Type']; 

}

}

+0

再次空白或... – 2014-09-06 19:19:58

+0

它工作正常 – Algobasket 2014-09-06 19:24:24

+0

http://awesomescreenshot.com/0863fwk86a – Algobasket 2014-09-06 19:26:56