您也可以解碼JSON使用json_decode()
這將給你的PHP變量,你可以很容易地使用PHP迭代。
例如。
$string = '{"image":"fox.png","puzzlepieces":{"f":{"puzzlepiece":"one","position":"top:121px;left:389px;"},"x":{"puzzlepiece":"three","position":"top:164px;left:455px;"},"o":{"puzzlepiece":"two","position":"top:52px;left:435px;"}}}';
var_dump(json_decode($string));
將輸出作爲
object(stdClass)[1]
public 'image' => string 'fox.png' (length=7)
public 'puzzlepieces' =>
object(stdClass)[2]
public 'f' =>
object(stdClass)[3]
public 'puzzlepiece' => string 'one' (length=3)
public 'position' => string 'top:121px;left:389px;' (length=21)
public 'x' =>
object(stdClass)[4]
public 'puzzlepiece' => string 'three' (length=5)
public 'position' => string 'top:164px;left:455px;' (length=21)
public 'o' =>
object(stdClass)[5]
public 'puzzlepiece' => string 'two' (length=3)
public 'position' => string 'top:52px;left:435px;' (length=20)
我Xdebug擴展是在WAMP讓你的var_dump可能會有點不同格式但總體來說,你會得到從u能重複使用數組PHP變量foreach
或其他循環。
瞭解更多關於json_decode here
您可以在參數做一個PHP函數與JSON數組,並調用該函數,如果電流值'is_array',打印別的! – JoDev 2013-04-05 09:29:44