PHP不使用'json_decode()'转换JSON [英] PHP not converting JSON using 'json_decode()'

查看:108
本文介绍了PHP不使用'json_decode()'转换JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些非常简单的代码

I have a very simple bit of code

$pc1 = $_POST['post_code1'];
$pc2 = $_POST['post_code2'];
$url = "http://maps.google.com/maps/nav?q=from:".$pc1."%20to:".$pc2;
$url_data = file_get_contents($url);
$json_data = json_decode($url_data);
var_dump($json_data);

$url_data充满了多汁的json内容,但$json_data返回了NULL.有人知道为什么吗?

$url_data is full of juicy json stuff but $json_data returns NULL. Does anyone have an idea why?

推荐答案

在找到了许多有类似问题的人之后,我发现以下方法可行

I found the following worked after find a number of people with similar problems

$json_data = json_decode(utf8_encode($url_data),true);

这篇关于PHP不使用'json_decode()'转换JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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