第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

從 json 中的子行中刪除方括號(hào)

從 json 中的子行中刪除方括號(hào)

PHP
九州編程 2023-07-08 21:43:07
我正在嘗試在網(wǎng)站上顯示以下數(shù)據(jù):-"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}我提取除天氣部分中的條目之外的任何條目,因?yàn)槲沂褂玫拇a認(rèn)為天氣數(shù)據(jù)是一個(gè)單獨(dú)的數(shù)組。與顯示數(shù)據(jù)相關(guān)的代碼部分是:-<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>第一行顯示數(shù)據(jù)正常,但天氣部分中的任何內(nèi)容都無(wú)法顯示任何內(nèi)容。我已經(jīng)看到了刪除所有方括號(hào)的解決方案,但它只需要圍繞天氣部分的括號(hào)。提前致謝
查看完整描述

2 回答

?
慕尼黑的夜晚無(wú)繁華

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊

下面的代碼 json_decodes 并回顯云和天氣數(shù)組。'希望能幫助到你。請(qǐng)給出意見(jiàn)。謝謝。


<?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."; ";

}


?>

輸出:


90

id=500; main=Rain; description=light rain; icon=10d; 

http://img1.sycdn.imooc.com//64a9680f0001002006530169.jpg

查看完整回答
反對(duì) 回復(fù) 2023-07-08
?
Smart貓小萌

TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊

在這種情況下,您必須使用json_decode將 json 字符串轉(zhuǎn)換為關(guān)聯(lián)數(shù)組。


$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

print_r如果您想知道數(shù)組索引是如何工作的,您可以從代碼中使用它,只需將其從注釋中刪除即可。


查看完整回答
反對(duì) 回復(fù) 2023-07-08
  • 2 回答
  • 0 關(guān)注
  • 194 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)