我该怎么读这篇文章呢?
[{"profile":"Admin","Cpt_profile":"3"},
{"profile":"Consultant","Cpt_profile":"1"}] 在php请我想有,
profile : admin
cpt_profile : 3 和
profile :consultant
cpt_profile :1 发布于 2016-05-20 17:38:06
正如前面所解释的。
<?php
$json = json_decode('[{"profile":"Admin","Cpt_profile":"3"},{"profile":"Consultant","Cpt_profile":"1"}] ',true);
// print_r($json);
foreach($json as $j)
{
print_r($j);
print 'profile:'.$j['profile']."\r\n";
print 'Cpt_profile:'.$j['Cpt_profile']."\r\n\r\n";
}
?>要调用每一行,请使用"foreach“,如下所示
发布于 2016-05-20 17:26:45
字符串是JSON,只需使用json_decode()返回一个数组,如下所示:
$json = '[{"profile":"Admin","Cpt_profile":"3"},{"profile":"Consultant","Cpt_profile":"1"}]';
$data = json_decode($json, true);
print_r($data);
// Will return
// Array
// (
// [0] => Array
// (
// [profile] => Admin
// [Cpt_profile] => 3
// )
// [1] => Array
// (
// [profile] => Consultant
// [Cpt_profile] => 1
// )
// )https://stackoverflow.com/questions/37342846
复制相似问题