我有这个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
?>
答案 0 :(得分:0)
您可以通过两种方式使用json对象:
<强> 1。 json对象样式:
echo $ json-&gt; geonams-&gt; name;
<强> 2。数组样式:
s="I loooooooooooooooooove you"
s = re.sub(r'(.)\1+', r'\1', s) // s= "I love you"