PHP中的简单JSON请求 [英] Simple JSON request in PHP

查看:129
本文介绍了PHP中的简单JSON请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下json

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

我只想要country_code,我该如何解析?

and i want just the country_code, how do i parse it?

我有这个代码

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

var_dump(json_decode($jsonfile));
?>

它返回NULL,为什么?

and it returns NULL, why?

谢谢.

推荐答案

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

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

You just need json not jsonp.
You can also try using json_decode($json, true) if you want to return the array.

这篇关于PHP中的简单JSON请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆