2

我需要使用 geonames api 获取所有国家/地区。我可以$geonames->genomes[2]->countryName用来获取第二个国家名称。但我希望它自动像while()我如何while()在 php 中使用它一样?

JSON 在这里 {"geonames":[{"countryName":"Andorra","currencyCode":"EUR","fipsCode":"AN","countryCode":"AD","isoNumeric":"020","north":42.65604389629997,"capital":"Andorra la Vella","continentName":"Europe","areaInSqKm":"468.0","languages":"ca","isoAlpha3":"AND","continent":"EU","south":42.42849259876837,"east":1.7865427778319827,"geonameId":3041565,"west":1.4071867141112762,"population":"84000"},{"countryName":"United Arab Emirates","currencyCode":"AED","fipsCode":"AE","countryCode":"AE","isoNumeric":"784","north":26.08415985107422,"capital":"Abu Dhabi","continentName":"Asia","areaInSqKm":"82880.0","languages":"ar-AE,fa,en,hi,ur","isoAlpha3":"ARE","continent":"AS","south":22.633329391479492,"east":56.38166046142578,"geonameId":290557,"west":51.58332824707031,"population":"4975593"}]}

4

2 回答 2

1

我们有一个 CSV 文件,其中包含世界上所有国家/地区、它们相应的 ISO 代码以及它们的英文、法文、西班牙文、俄文、中文、阿拉伯文和意大利文的简称和正式名称。这是根据各种政府和国际参考资料汇编而成的:

http://www.opengeocode.org/download/countrynames.txt

参考文献引用于:

http://www.opengeocode.org/download.php#countrynames

于 2013-11-30T07:19:31.453 回答
0

您可以使用 for 循环:

for ($i = 0; $i < $numCountries; $i++) {
  echo $geonames->geonames[$i]->countryName;
}
于 2013-10-17T16:40:51.220 回答