繁体   English   中英

如何从对象数组获取json字符串

[英]How to get json string from an array of object

以下代码给出了一个带有json对象的数组。 但是我需要该数组的json字符串,以便以后可以使用json_decode。 怎么做?

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"}]
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'=>json_decode($goalids),'length'=>$game['length']));
            break;
        }
    }
}
$json_string=json_encode($text);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM