Answer the question
In order to leave comments, you need to log in
How to return in json?
There is a php code that needs to be returned in json format, how to do it?
echo('city: '.$city['city']['name_en'].'<br>');
echo('city code: '.$city['city']['id'].'<br>');
echo('city lat: '.$city['city']['lat'].'<br>');
echo('city lon: '.$city['city']['lon'].'<br>');
echo('country: '.$city['country']['name_en'].'<br>');
echo('country iso: '.$city['country']['iso'].'<br>');
echo('country code: '.$city['country']['id'].'<br>');
$arr = array('IP' => $ip,
'city' => $city['city']['name_en'],
'city code' => $city['city']['id'],
'city lat' => $city['city']['lat'],
'city lon' => $city['city']['lon'],
'country' => $city['country']['name_en'],
'country iso' => $city['country']['iso'],
'country code' => $city['country']['id'],);
echo json_encode($arr);
Answer the question
In order to leave comments, you need to log in
You can use the JSON_PRETTY_PRINT
JSON constants flag
$arr = array('IP' => $ip,
'city' => $city['city']['name_en'],
'city code' => $city['city']['id'],
'city lat' => $city['city']['lat'],
'city lon' => $city['city']['lon'],
'country' => $city['country']['name_en'],
'country iso' => $city['country']['iso'],
'country code' => $city['country']['id'],);
echo json_encode($arr, JSON_PRETTY_PRINT);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question