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

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

Geonames api 循環(huán)并獲取城市名稱

Geonames api 循環(huán)并獲取城市名稱

PHP
滄海一幻覺(jué) 2023-10-15 16:23:09
$jsonfile = file_get_contents("http://api.geonames.org/searchJSON?username=ksuhiyp&country=pt&maxRows=1000&style=SHORT");    $jsondata = json_encode($jsonfile);    $cities = explode(',', $jsondata);    foreach($cities as $key => $value){        echo $value;    }我怎樣才能只獲取數(shù)組中包含的所有城市名稱(例如......里斯本,波爾圖,阿威羅......)?這是數(shù)組的示例:{"totalResultsCount":37305,"geonames":[{"lng":"-9.13333","geonameId":2267057,"countryCode":"PT","name":"Lisbon","toponymName":"Lisbon","lat":"38.71667","fcl":"P","fcode":"PPLC"},{"lng":"-8.61099","geonameId":2735943,"countryCode":"PT","name":"Porto","toponymName":"Porto","lat":"41.14961","fcl":"P","fcode":"PPLA"},{"lng":"-8.42005","geonameId":2742032,"countryCode":"PT","name":"Braga","toponymName":"Braga","lat":"41.55032","fcl":"P","fcode":"PPLA"},{"lng":"-8.8882","geonameId":2262963,"countryCode":"PT","name":"Setúbal","toponymName":"Setúbal","lat":"38.5244","fcl":"P","fcode":"PPLA"},{"lng":"-8.13057","geonameId":2264397,"countryCode":"PT","name":"Portugal","toponymName":"Portuguese Republic","lat":"39.6945","fcl":"A","fcode":"PCLI"},
查看完整描述

1 回答

?
慕的地8271018

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

對(duì)于初學(xué)者來(lái)說(shuō),這是一種非常丑陋的獲取數(shù)據(jù)的方式,因?yàn)槟趯?duì)已經(jīng)是 json 的 json 數(shù)據(jù)進(jìn)行編碼,然后僅循環(huán)生成的損壞字符串的片段。


這將為您提供一個(gè)僅包含名稱的結(jié)果數(shù)組:


$jsonfile = file_get_contents("http://api.geonames.org/searchJSON?username=ksuhiyp&country=pt&maxRows=1000&style=SHORT");

$geodat = json_decode($jsonfile,true);

$names = array();

foreach($geodat['geonames'] as $geoname) {

    $names[] = $geoname['name'];

}

print_r($names);

輸出示例:


Array (

    [0] => Lisbon

    [1] => Porto

    [2] => Braga

    [3] => Setúbal

    [4] => Portugal

    [5] => Coimbra

    [6] => Funchal

    [7] => Amadora

    [8] => Queluz

    [9] => Lisbon metropolitan area

    ...


查看完整回答
反對(duì) 回復(fù) 2023-10-15
  • 1 回答
  • 0 關(guān)注
  • 337 瀏覽

添加回答

舉報(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)