file_get_contents php and json_decode error

前端 未结 2 688
庸人自扰
庸人自扰 2021-01-22 08:29

I am facing a weird problem with file_get_contents and decoding to json the result. I have to tell you that this code was fully functional in other server.

相关标签:
2条回答
  • 2021-01-22 09:14

    The json is simply invalid.

    In front of the first opening curly braces there is the following content (hex encoded) ef bb bf ef bb bf

    It is the utf8 bom.

    There is a question related to deal with exactly that, so I will not cover it here. Read up here:

    How to remove %EF%BB%BF in a PHP string

    and another one dealing specifically with json here:

    Convert UTF-8 with BOM to UTF-8 with no BOM in Python

    0 讨论(0)
  • 2021-01-22 09:22

    Try to give JSON URL in the http://jsonlint.com/ and than copy the response and paste it in a file with BOM disabled you will notice that there is a strange small line in the beginning before the opening { bracket which is causing the issues

    0 讨论(0)
提交回复
热议问题