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

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

报告相同问题?

悬赏问题

  • ¥100 只改动本课件的 cal_portfolio_weight_series(decision_date), 跑完本课件。设计一个信息比率尽量高的策略。
  • ¥20 如何在visual studio 2022中添加ImageMagick库
  • ¥50 如何实现uniapp编译的微信小程序做可回溯视频
  • ¥15 求Houdini使用行家,付费。价格面议。
  • ¥15 前端高拍仪调用问题报错
  • ¥15 想用octave解决这个数学问题
  • ¥15 Centos新建的临时ip无法上网,如何解决?
  • ¥15 海康威视如何实现客户端软件对设备语音请求的处理。
  • ¥15 支付宝h5参数如何实现跳转
  • ¥15 MATLAB代码补全插值