ECHO JSON用PHP

我有这样的JSON和我需要从它呼应了一些具体的结果与PHPECHO JSON用PHP

JSON

{ 

totalResultsCount: 1,

geonames: [

{

adminCode1: "06",

lng: "27.85849",

geonameId: 953781,

toponymName: "Soweto",

countryId: "953987",

fcl: "P",

population: 1695047,

countryCode: "ZA",

name: "Soweto",

fclName: "city, village,...",

countryName: "South Africa",

fcodeName: "populated place",

adminName1: "Gauteng",

lat: "-26.26781",

fcode: "PPL"

}

]

}

我将如何回应让说名字是在GEONAMES []

我想这

<?php 

echo $json->geonams->name

?>

回答:

您可以通过两种方式使用JSON对象:

1. JSON对象风格:

回声$ json-> geonams->名称;

2.数组风格:

$arr = json_decode($json, true); // it will return an array 

echo $arr['geonams']['name'];

以上是 ECHO JSON用PHP 的全部内容, 来源链接: utcz.com/qa/265354.html

回到顶部