Php 从json中的子行中删除方括号

Php 从json中的子行中删除方括号,php,arrays,json,square-bracket,Php,Arrays,Json,Square Bracket,我试图在网站上显示以下数据:- "daily":[{"dt":1593864000,"sunrise":1593834201,"sunset":1593894929,"temp":{"day":18.47,"min":17.83,"max":18.71,"night":17.83,"eve":18.

我试图在网站上显示以下数据:-

"daily":[{"dt":1593864000,"sunrise":1593834201,"sunset":1593894929,"temp":{"day":18.47,"min":17.83,"max":18.71,"night":17.83,"eve":18.71,"morn":18.47},"feels_like":{"day":16,"night":13.09,"eve":16.54,"morn":16},"pressure":1006,"humidity":77,"dew_point":14.37,"wind_speed":5.51,"wind_deg":244,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":90,"uvi":7.08}
我提取除weather部分之外的任何条目,因为我使用的代码认为天气数据是一个单独的数组

与显示数据相关的代码部分为:-

<span class="min-temperature">&nbsp;Minimum Temperature&nbsp;<?php echo $data->daily[0]->clouds; ?>&deg;C</span><br>
  <span class="min-temperature">&nbsp;Pressure&nbsp;<?php echo $data->daily[0]->weather->id; ?></span>
最低温度°;C
压力
第一行显示数据很好,但天气部分中的任何内容都无法显示任何内容

我已经看到了移除所有方括号的解决方案,但它只是围绕天气部分的括号


提前感谢

下面的代码将对云和天气阵列进行解码和回音希望能有帮助。请评论。多谢各位

<?php 

$data=json_decode( '{"daily":{"dt":1593864000,"sunrise":1593834201,"sunset":1593894929,"temp":{"day":18.47,"min":17.83,"max":18.71,"night":17.83,"eve":18.71,"morn":18.47},"feels_like":{"day":16,"night":13.09,"eve":16.54,"morn":16},"pressure":1006,"humidity":77,"dew_point":14.37,"wind_speed":5.51,"wind_deg":244,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":90,"uvi":7.08}}'); # define $data as a stdClass Object
echo $data->daily->clouds;
echo "\n";

# below, weather array is converted into a string
$wa=(array)$data->daily->weather[0];
foreach($wa as $key=> $val){
    echo $key."=".$val."; ";
}

?>

在本例中,必须使用
json\u decode
将json字符串转换为关联数组

$data = '{"daily":{"dt":1593864000,"sunrise":1593834201,"sunset":1593894929,"temp":{"day":18.47,"min":17.83,"max":18.71,"night":17.83,"eve":18.71,"morn":18.47},"feels_like":{"day":16,"night":13.09,"eve":16.54,"morn":16},"pressure":1006,"humidity":77,"dew_point":14.37,"wind_speed":5.51,"wind_deg":244,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":90,"uvi":7.08}}';
$decode = json_decode($data,true);
echo '<pre>';
//print_r($decode);
echo $decode['daily']['clouds'].'<br>';
echo $decode['daily']['uvi'].'<br>';

echo $decode['daily']['weather'][0]['id'].'<br>';
echo $decode['daily']['weather'][0]['main'].'<br>';  //These three are from weather array. 
echo $decode['daily']['weather'][0]['description'].'<br>';
echo '<pre>';

如果您想知道数组索引是如何工作的,您可以从代码中使用
print\r
,只需将其从注释中删除即可。

我认为您需要显示
$data->daily[0]->weather[0]->id
。顺便说一句,我建议不要在标记中使用
,而是使用css控制格式,键入“min temperature”类。这个JSON不有效。我想,我只需要在天气结束时添加[0]就可以了,我肯定我已经尝试过了,但现在已经排序了。我将在整理过程中查看不间断空间。感谢Rupert,是[0]错过了天气,这才是问题所在。很高兴知道现在一切都好了,Paul。也感谢库奈在下面的讲话。谢谢,库纳尔。代码部分只是代码的一部分,json_解码已经存在于代码中。(我很抱歉没有发布完整的代码很高兴能帮助你@Paul
$data = '{"daily":{"dt":1593864000,"sunrise":1593834201,"sunset":1593894929,"temp":{"day":18.47,"min":17.83,"max":18.71,"night":17.83,"eve":18.71,"morn":18.47},"feels_like":{"day":16,"night":13.09,"eve":16.54,"morn":16},"pressure":1006,"humidity":77,"dew_point":14.37,"wind_speed":5.51,"wind_deg":244,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":90,"uvi":7.08}}';
$decode = json_decode($data,true);
echo '<pre>';
//print_r($decode);
echo $decode['daily']['clouds'].'<br>';
echo $decode['daily']['uvi'].'<br>';

echo $decode['daily']['weather'][0]['id'].'<br>';
echo $decode['daily']['weather'][0]['main'].'<br>';  //These three are from weather array. 
echo $decode['daily']['weather'][0]['description'].'<br>';
echo '<pre>';
90
7.08
500
Rain
light rain