gpt4 book ai didi

php - PHP 中的简单 JSON 请求

转载 作者:IT王子 更新时间:2023-10-29 00:09:51 25 4
gpt4 key购买 nike

我有以下 json

country_code({"latitude":"45.9390","longitude":"24.9811","zoom":6,"address":{"city":"-","country":"Romania","country_code":"RO","region":"-"}})

我只想要国家代码,我该如何解析它?

我有这个代码

<?php
$json = "http://api.wipmania.com/jsonp?callback=jsonpCallback";
$jsonfile = file_get_contents($json);

var_dump(json_decode($jsonfile));
?>

它返回 NULL,为什么?

谢谢。

最佳答案

<?php
$jsonurl = "http://api.wipmania.com/json";
$json = file_get_contents($jsonurl);
var_dump(json_decode($json));
?>

你只需要 json 而不是 jsonp。
如果要返回数组,也可以尝试使用 json_decode($json, true)

关于php - PHP 中的简单 JSON 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9930434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com