2016-11-23 77 views
0

我有一個來自import.io的json文件,解碼時返回null,但在編碼時顯示爲字符串,並且全部存在。我怎樣才能通過PHP中的json字符串「循環」?通過PHP解析字符串格式的JSON

Json數據非常冗長,所以我沒有發佈它。

JSON:https://codeshare.io/2BD4ma

代碼:

<?php 

$jsonFile = file_get_contents('feeds/quotes.json'); 

//decode 
$results = json_encode($jsonFile, TRUE); 

var_dump($results); 


?> 
+0

也許回答以前ously? http://stackoverflow.com/questions/5164404/json-decode-to-array –

+0

發佈樣本json和你試過的示例代碼 – Elby

+0

看看http://www.dyn-web.com/tutorials/php- js/json/decode.php –

回答

1

這將是很高興看到你正在使用的代碼,或試圖....

無論哪種方式,你需要使用json_decode上的JSON對象,它會將它變成一個PHP數組:

$data = json_decode($yourJsonData); 

// print_r it to see: 
print_r($data); 

// to loop through it, you could do: 
foreach ($data as $item) 
{ 
    print_r($item); // used print_r: unsure if this data will contain nested objects/arrays 
} 
+0

我試過這個,但每次使用解碼時數據都是空的。 – user1721449

+0

THat看起來不像格式正確的JSON。你確定它沒有被序列化/在這個過程中的某個地方逃脫? – Stuart

+0

不知道有無論如何說。它是由import.io – user1721449