Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 来自API REST的json dat_Php_Arrays_Json - Fatal编程技术网

Php 来自API REST的json dat

Php 来自API REST的json dat,php,arrays,json,Php,Arrays,Json,从API调用中,我获得JSON格式的数据 现在我想使用这些数据并创建这些代码 <?php $result = json_decode($content); echo $result->price; ?> 例如,如何获取价格?在使用JSON时,使用关联数组更简单,尤其是在使用嵌套JSON时 如果您的JSON对象嵌套如下: { "short_description":{ "sku":3463031, "price":144.00, ... } } 您可以使用以下方式访问它:

从API调用中,我获得JSON格式的数据 现在我想使用这些数据并创建这些代码

<?php
$result  = json_decode($content);

echo $result->price;
?>

例如,如何获取价格?

在使用JSON时,使用关联数组更简单,尤其是在使用嵌套JSON时

如果您的JSON对象嵌套如下:

{
"short_description":{
"sku":3463031,
"price":144.00,
...
}
}
您可以使用以下方式访问它:

$result=json_decode($content,true);  //true converts returned object to an associative array
echo $result['short_description']['price'];
如果没有,请在下面使用:

$result=json_decode($content,true);  //true converts returned object to an associative array
echo $result['price'];

使用JSON时,使用关联数组更简单,尤其是当您使用嵌套JSON时

如果您的JSON对象嵌套如下:

{
"short_description":{
"sku":3463031,
"price":144.00,
...
}
}
您可以使用以下方式访问它:

$result=json_decode($content,true);  //true converts returned object to an associative array
echo $result['short_description']['price'];
如果没有,请在下面使用:

$result=json_decode($content,true);  //true converts returned object to an associative array
echo $result['price'];

使用
json\u解码($content,true)使用
json\u解码($content,true)取而代之。感谢您提供此代码段,它可能会提供一些有限的、即时的帮助。通过展示为什么这是一个很好的问题解决方案,A将极大地提高它的长期价值,并将使它对未来有其他类似问题的读者更有用。请在您的答案中添加一些解释,包括您所做的假设。感谢您提供此代码片段,它可能会提供一些有限的、即时的帮助。通过展示为什么这是一个很好的问题解决方案,A将极大地提高它的长期价值,并将使它对未来有其他类似问题的读者更有用。请在您的回答中添加一些解释,包括您所做的假设。