[英]how to fetch data from json array in php
我正在尝试从PHP变量中的以下JSON数组获取值。
这是数组的var_dump:
array(1) { [0]=> object(stdClass)#1 (1) { ["row"]=> object(stdClass)#2 (1) { ["u_fname"]=> string(6) "Ashish" } } }
这是我的页面代码。 $
字符只是window.jQuery
的快捷方式。
$contents = file_get_contents('http://localhost/skillbook/json.php');
$contents = utf8_encode($contents);
$results =var_dump(json_decode($contents));
?>
$contents = file_get_contents('http://localhost/skillbook/json.php');
$contents = utf8_encode($contents);
$contents_array = json_decode($contents,1);
$foundvalue= $contents_array[0]["row"]["u_fname"];
echo $foundvalue;
输出: Ashish
我认为你可以为json使用foreach条件
$json = file_get_contents('http://localhost/skillbook/json.php');
$json = utf8_encode($json);
$data = json_decode($json,true);
// change the variable name to devices which is clearer.
$devices = $data['0'];
foreach ($devices as $device)
{
echo $device["u_fname"];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.