将Json std对象转换为数组



我有这样的json

{"status":"TRUE","flag":1,"message":"Has Data","data":[{"country_id":"1","country_name":"India"}]}

这是我从api中得到的返回值。我需要将其转换为数组,并且需要值country_id和country_name。

我尝试使用转换,但无法将其解析为数组

json_decode(); 

但我仍然使用std对象格式。有人帮我。提前谢谢。

在模型中,我正在返回中的值

return $Result->result_array()

使用json_decode($json, true)

$json = '{"status":"TRUE","flag":1,"message":"Has Data","data":[{"country_id":"1","country_name":"India"}]}';
$array = json_decode($json,TRUE);
echo $array['data'][0]['country_id'].PHP_EOL;
echo $array['data'][0]['country_name'];

请参阅工作演示:https://eval.in/1040313

输出

1
India

最新更新