Php 来自API REST的json dat
从API调用中,我获得JSON格式的数据 现在我想使用这些数据并创建这些代码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, ... } } 您可以使用以下方式访问它:
<?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)改为code>使用json\u解码($content,true)代码>取而代之。感谢您提供此代码段,它可能会提供一些有限的、即时的帮助。通过展示为什么这是一个很好的问题解决方案,A将极大地提高它的长期价值,并将使它对未来有其他类似问题的读者更有用。请在您的答案中添加一些解释,包括您所做的假设。感谢您提供此代码片段,它可能会提供一些有限的、即时的帮助。通过展示为什么这是一个很好的问题解决方案,A将极大地提高它的长期价值,并将使它对未来有其他类似问题的读者更有用。请在您的回答中添加一些解释,包括您所做的假设。