下面的代碼給出了一個帶有json對象的數組。但是我需要該數組的json字符串,以便以後可以使用json_decode。怎麼做?如何從對象數組中獲取json字符串
for($i=0;$i<5;$i++)
{ foreach($allGames as $game)
{ if($game['desc']==$sortGames[$i])
{ $text[$i]=array('Game_name'=>$game['desc'],'GameId'=>$game['gameId'],'order'=>$goalids,'length'=>$game['length']);
break;
}
}
}
$json_string=json_encode($text);
$ json_string的值如下:
[{"Game_name":"a","GameId":"1697","order":["11022","11021","11020","11024","11023"],"length":"2.08783938975344"},{"Game_name":"b","GameId":"1800","order":["12196","12197","12194","12195","12193","12198"],"length":"1.16970835124072"}]
什麼ü平均排列的JSON字符串?在結果中你已經得到字符串 – bxN5
結果是json數組。 json_decode無法解碼它。 – LSG
所以問題是你不能解碼編碼的字符串? – bxN5