搜尋
首頁後端開發php教程json_decode为空问题

json_decode为空问题

Jun 13, 2016 am 10:30 AM
jsonjson_decode

<span style="font-family: 微软雅黑,Microsoft YaHei;">在error_log日志中打出 json_last_error() 和 json_last_error_msg()</span>

<span style="font-family: 微软雅黑,Microsoft YaHei;">发现 4 和 'Syntax error'</span><span style="font-family: 微软雅黑,Microsoft YaHei;"><br></span>

<span style="font-family: 微软雅黑,Microsoft YaHei;">可以用base64_encode记录下要解的$response数据  然后在本地base64_decode出来 </span><code><span style="font-family: 微软雅黑,Microsoft YaHei;">再进行json_decode</span>  查为什么不能解开<br>

<span style="font-family: 微软雅黑,Microsoft YaHei;">测试了</span>

<code class="Brush variable"><span style="font-family: 微软雅黑,Microsoft YaHei;">$json</span> <code class="Brush plain"><span style="font-family: 微软雅黑,Microsoft YaHei;">= iconv(</span><span style="font-family: 微软雅黑,Microsoft YaHei;">'GBK'</span><code class="Brush plain"><span style="font-family: 微软雅黑,Microsoft YaHei;">,</span><span style="font-family: 微软雅黑,Microsoft YaHei;">'utf-8'</span><code class="Brush plain"><span style="font-family: 微软雅黑,Microsoft YaHei;">,</span><code class="Brush variable"><span style="font-family: 微软雅黑,Microsoft YaHei;">$json</span><code class="Brush plain"><span style="font-family: 微软雅黑,Microsoft YaHei;">);</span>

<code class="Brush plain">$json = stripslashes($json);<br>

<code class="Brush plain"><span style="font-family: 微软雅黑,Microsoft YaHei;">$json = htmlspecialchars_decode($json);</span>

<span style="font-family: 微软雅黑,Microsoft YaHei;">等多种方法 都不行 </span><br>

<span style="font-family: 微软雅黑,Microsoft YaHei;">最后发现返回的response数据有bom头字符</span><br>

$response = trim($response,chr(239).chr(187).chr(191));<br>$response = json_decode($response, true);<br>

<span style="font-family: 微软雅黑,Microsoft YaHei;">这样正常解开了</span><br>

<code><span style="font-family: 微软雅黑,Microsoft YaHei;">base64_decode出来</span>的json数据有没有bom头字符 除了网上说的其它方法  也可以放到json在线编辑器中查看<br>

附:<br>

json_decode要求的字符串比较严格:<br>(1)使用UTF-8编码<br>(2)不能在最后元素有逗号<br>(3)不能使用单引号<br>(4)不能有\r,\t,如果有请替换

更多相关教程请访问 php编程从入门到精通全套视频教程<br>

陳述
本文轉載於:CSDN博客。如有侵權,請聯絡admin@php.cn刪除
如何使PHP應用程序更快如何使PHP應用程序更快May 12, 2025 am 12:12 AM

tomakephpapplicationsfaster,關注台詞:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

PHP性能優化清單:立即提高速度PHP性能優化清單:立即提高速度May 12, 2025 am 12:07 AM

到ImprovephPapplicationspeed,關注台詞:1)啟用opcodeCachingwithapCutoredUcescriptexecutiontime.2)實現databasequerycachingingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandreduceconnection.4 limitesclection.4.4

PHP依賴注入:提高代碼可檢驗性PHP依賴注入:提高代碼可檢驗性May 12, 2025 am 12:03 AM

依赖注入(DI)通过显式传递依赖关系,显著提升了PHP代码的可测试性。1)DI解耦类与具体实现,使测试和维护更灵活。2)三种类型中,构造函数注入明确表达依赖,保持状态一致。3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

PHP性能優化:數據庫查詢優化PHP性能優化:數據庫查詢優化May 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

簡單指南:帶有PHP腳本的電子郵件發送簡單指南:帶有PHP腳本的電子郵件發送May 12, 2025 am 12:02 AM

phpisusedforsenderemailsduetoitsbuilt-inmail()函數andsupportivelibrariesLikePhpMailerAndSwiftMailer.1)usethemail()functionForbasiceMails,butithasimails.2)butithasimail.2)

PHP性能:識別和修復瓶頸PHP性能:識別和修復瓶頸May 11, 2025 am 12:13 AM

PHP性能瓶颈可以通过以下步骤解决:1)使用Xdebug或Blackfire进行性能分析,找出问题所在;2)优化数据库查询并使用缓存,如APCu;3)使用array_filter等高效函数优化数组操作;4)配置OPcache进行字节码缓存;5)优化前端,如减少HTTP请求和优化图片;6)持续监控和优化性能。通过这些方法,可以显著提升PHP应用的性能。

PHP的依賴注入:快速摘要PHP的依賴注入:快速摘要May 11, 2025 am 12:09 AM

依賴性注射(DI)InphpisadesignPatternthatManages和ReducesClassDeptions,增強量強制性,可驗證性和MATIALWINABIOS.ItallowSpasspassingDepentenciesLikEdenciesLikedAbaseConnectionStoclasseconnectionStoclasseSasasasasareTers,interitationAseTestingEaseTestingEaseTestingEaseTestingEasingAndScalability。

提高PHP性能:緩存策略和技術提高PHP性能:緩存策略和技術May 11, 2025 am 12:08 AM

cachingimprovesphpermenceByStorcyResultSofComputationsorqucrouctationsorquctationsorquickretrieval,reducingServerLoadAndenHancingResponsetimes.feftectivestrategiesinclude:1)opcodecaching,whereStoresCompiledSinmememorytssinmemorytoskipcompliation; 2)datacaching datacachingsingMemccachingmcachingmcachings

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。