我將這個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 ,它是完全有效的。怎么了解在Google上尋找答案,我回到SO:調用webservice后json_decode返回NULL。我的JSON文件具有UTF BOM序列(一些不應包含的二進制字符),因此破壞了JSON結構。進入十六進制編輯器,刪除了字節。一切恢復正常。為什么會這樣呢?因為我使用Microsoft Windows的記事本編輯了文件。好主意!
- 3 回答
- 0 關注
- 1063 瀏覽
添加回答
舉報
0/150
提交
取消