从json检索属性?PHP
我有一个部分json:从json检索属性?PHP,php,json,Php,Json,我有一个部分json: string(1583) "[{"user_id":"U4qtgydvSgG9zV9F"}] 如何获取用户id值 我试过这个: $json = json_decode($res); $UserId = $res->user_id; 但是我没有点击用户id 然后,我尝试将结果强制转换为一个数组,以访问用户id,如下所示: $res = (array)file_get_contents($url, false, $context); echo $res['user_
string(1583) "[{"user_id":"U4qtgydvSgG9zV9F"}]
如何获取用户id值
我试过这个:
$json = json_decode($res);
$UserId = $res->user_id;
但是我没有点击用户id
然后,我尝试将结果强制转换为一个数组,以访问用户id,如下所示:
$res = (array)file_get_contents($url, false, $context);
echo $res['user_id'];
array(1) { [0]=> string(1583) "[{"user_id":"U4qtgydvSgG9zV9F-NB2rQ"
该数组如下所示:
$res = (array)file_get_contents($url, false, $context);
echo $res['user_id'];
array(1) { [0]=> string(1583) "[{"user_id":"U4qtgydvSgG9zV9F-NB2rQ"
如何获取用户id值?谢谢请参见此json示例:
$j = '[{"user_id":"U4qtgydvSgG9zV9F"}]';
$j = json_decode($j);
echo $j[0]->user_id;
试试这个:
$UserId=$res[0]->user\u id代码>您发布的JSON字符串无效,如果没有其他字符串,则无法查看结构。首先需要去掉“string(1583)”部分,因为这不是JSON的一部分。json字符串来自何处,在我看来,它像是var_dump()的结果。