Parsing ambiguous results in PHP

  • 1
  • Problem
  • Updated 5 years ago
A few days ago, I started receiving an ambiguous response to my autoip query :

"results": [
{
"name": "Sherbrooke",
"city": "Sherbrooke",
"state": "QB",
"country": "CA",
"country_iso3166":"CA",
"country_name":"",
"zmw": "00000.1.WCYSC",
"l": "/q/zmw:00000.1.WCYSC"
}
,
{
"name": "Sherbrooke",
"city": "Sherbrooke",
"state": "QC",
"country": "CA",
"country_iso3166":"CA",
"country_name":"",
"zmw": "00000.1.71610",
"l": "/q/zmw:00000.1.71610"
}
]

I'm not trying to parse it to re-query the server for the first result returned, and for that, I need to get the "l" value. However, I seem to be incapable of doing so. Here's my script in PHP :

$json_string = file_get_contents($data_URL); // query using autoip
$parsed_json = json_decode($json_string);

echo $parsed_json->results[0]->l;

Absolutely nothing gets echoed on the terminal...

Any help with this problem?

Thanks!
Photo of samric

samric

  • 2 Posts
  • 0 Reply Likes

Posted 5 years ago

  • 1
Photo of samric

samric

  • 2 Posts
  • 0 Reply Likes
Typo. It should read like this :

"I'm trying to parse it to re-query the server for the first result returned, and for that, I need to get the "l" value."

Sorry....
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
seems you missing a "path piece", so the followinf code shall work
echo $parsed_json->response->results[0]->l;
Photo of Brendan Hayes

Brendan Hayes, Official Rep

  • 962 Posts
  • 123 Reply Likes
autoip should work now without an ambiguous result