2016-10-04 16 views

回答

4

返回你的數組與json_encode($array)它將返回一個JSON對象。

+0

這實際上是JSON設計的目的。 – apokryfos

+0

@Mohamed Nizar,你能解釋我具體是什麼意思嗎? –

+0

如果你讀過'file_get_contents('yourfilename.php')',它應該返回json_encode($ array)'你將訪問你的json對象 –

1

@穆罕默德·尼扎爾建設上,

filename.php:

<html> 
<head> 
<script> 
var json = <?php json_encode(file_get_contents('array.php')); ?>; 
</script> 
</head> 
<body> 
</body> 
</html> 

用於轉換到JSON和Javascript陣列(),檢查此線程:How to convert JSON to Array 但真的沒有理由這樣做,最好只使用JSON。