PHP json_decode() 用看似有效的 JSON 返回 NULL?

标签 php json null

我将此 JSON 对象存储在纯文本文件中:

{
    "MySQL": {
        "Server": "(server)",
        "Username": "(user)",
        "Password": "(pwd)",
        "DatabaseName": "(dbname)"
    },
    "Ftp": {
        "Server": "(server)",
        "Username": "(user)",
        "Password": "(pwd)",
        "RootFolder": "(rf)"
    },
    "BasePath": "../../bin/",
    "NotesAppPath": "notas",
    "SearchAppPath": "buscar",
    "BaseUrl": "http:\/\/montemaiztusitio.com.ar",
    "InitialExtensions": [
        "nem.mysqlhandler",
        "nem.string",
        "nem.colour",
        "nem.filesystem",
        "nem.rss",
        "nem.date",
        "nem.template",
        "nem.media",
        "nem.measuring",
        "nem.weather",
        "nem.currency"
    ],
    "MediaPath": "media",
    "MediaGalleriesTable": "journal_media_galleries",
    "MediaTable": "journal_media",
    "Journal": {
        "AllowedAdFileFormats": [
            "flv:1",
            "jpg:2",
            "gif:3",
            "png:4",
            "swf:5"
        ],
        "AdColumnId": "3",
        "RSSLinkFormat": "%DOMAIN%\/notas\/%YEAR%-%MONTH%-%DAY%\/%TITLE%/",
        "FrontendLayout": "Flat",
        "AdPath": "ad",
        "SiteTitle": "Monte Maíz: Tu Sitio",
        "GlobalSiteDescription": "Periódico local de Monte Maíz.",
        "MoreInfoAt": "Más información aquí, en el Periódico local de Monte Maíz.",
        "TemplatePath": "templates",
        "WeatherSource": "accuweather:SAM|AR|AR005|MONTE MAIZ",
        "WeatherMeasureType": "1",
        "CurrencySource": "cotizacion-monedas:Dolar|Euro|Real",
        "TimesSingular": "vez",
        "TimesPlural": "veces"
    }
}

当我尝试使用 json_decode() 对其进行解码时,它返回 NULL。为什么? 该文件是可读的(我尝试回显 file_get_contents() 并且它工作正常)。

我已经针对 http://jsonlint.com/ 测试了 JSON这是完全有效的。

这里有什么问题?

最佳答案

这对我有用

json_decode( preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $json_string), true );

关于PHP json_decode() 用看似有效的 JSON 返回 NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2410342/

相关文章:

json - 如何解析golang中的json数组?

json - 使用 pandas 在列中加载 Json 数据多个值

c# - C# 中的 Nullsafe 导航

mysql - 在子查询中处理 null

php - 父类引用仅存在于子类中的属性是否合适?

php - Mysql执行数据。为字符串选择什么分隔符,进一步分解以创建数组?

php - 在 mysql 上存储用户的最佳实践是什么?

java - Json_decode 返回 Null 和错误 4

php - 从表中的 json 中获取单个项目

Javascript 空检查似乎不起作用