dongna2498 2015-11-04 16:40
浏览 75
已采纳

无法在php中读取Json文件

I have a json file that i want to read but the json_decode function in php always returns error the error is number 5 the utf8 one i use the utf8_decode function and try again it gives error number 4 the syntex error one but although i check it on jsonint validator can you guys help me ? here is the json :

{
    "China": [
        "Guangzhou",
        "Fuzhou",
        "Beijing",
        "Baotou",
        "Hohhot",
        "Guiyang",
        "Yinchuan",
        "Nanjing",
        "Changzhou",
        "Chuzhou",
        "Hefei",
        "Jinan",
        "Qingdao",
        "Harbin",
        "Zhaodong",
        "Taiyuan",
        "Xi'an",
        "Xianyang",
        "Shenzhen",
        "Nanning",
        "Zhengzhou",
        "Xinxiang",
        "Luohe",
        "Luoyang",
        "Chaoyang",
        "Xingyi",
        "Foshan",
        "Haikou",
        "Chengdu",
        "Dongguan",
        "Mingzhou",
        "Chongqing",
        "Zhuhai",
        "Kunming",
        "Wuhan",
        "Xiling",
        "Huizhou",
        "Jiangmen",
        "Shantou",
        "Changxiacun",
        "Zhongshan",
        "Lhasa",
        "Nanchang",
        "Tianjin",
        "Shanghai",
        "Hebei",
        "Shijiazhuang",
        "Quanzhou",
        "Putian",
        "Xiamen",
        "Chengyang",
        "Zhangzhou",
        "Sanming",
        "Nanping",
        "Baoding",
        "Langfang",
        "Yantai",
        "Binzhou",
        "Lanzhou",
        "Yueqing",
        "Zhongxin",
        "Zhoushan",
        "Hangzhou",
        "Ningbo",
        "Wenzhou",
        "Changchun",
        "Fuyang",
        "Jieshou",
        "Anqing",
        "Wuhu",
        "Shishi",
        "Shishi",
        "Weitang",
        "Shenyang",
        "Changsha",
        "Yongjiawan",
        "Lengshuijiang",
        "Shijiazhuang",
        "Xuchang",
        "Suzhou",
        "Xuzhou",
        "Taizhou",
        "Nanyang",
        "Xinhua",
        "Ürümqi",
        "Yan'an Beilu",
        "Baotao",
        "Macao",
        "Wuxi",
        "Yangzhou",
        "Baiyin",
        "Tongren",
        "Kunshan",
        "Zhangjiagang"
    ]
}

and here is the php code :

<?php

$str=file_get_contents("countriesToCities.json");
$json =json_decode($str,true);
print_r( $json['China']);


?>
  • 写回答

1条回答 默认 最新

  • dongyan8929 2015-11-04 16:53
    关注

    I have the same problem when i'm using utf8 with bom. The simplest way is remove it for example by this: function

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 快手联盟怎么快速的跑出建立模型
  • ¥20 ros环境下运行orb-slam一直报错
  • ¥15 关于腾讯云服务器中,PHP页面无法打开的问题
  • ¥60 如何把照片修复成原始拍摄图
  • ¥80 Exited too quickly (process log may have details)
  • ¥15 爬知乎登录之后内容加载不出来
  • ¥15 怎么用protues测量通频带
  • ¥15 zepelin使用sparkInterpreter 异常
  • ¥15 paho mqtt 接收不到消息
  • ¥15 函数r关于两个分量y,z方向上的图像,分开画r随y的图像,r随z的图像