搜索
首页后端开发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>  查为什么不能解开<code><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 variable"><code class="Brush plain"><span style="font-family: 微软雅黑,Microsoft YaHei;">,</span>$json<span style="font-family: 微软雅黑,Microsoft YaHei;">'utf-8'</span><code class="Brush plain"><span style="font-family: 微软雅黑,Microsoft YaHei;">,</span> <code class="Brush plain"><code class="Brush variable"><span style="font-family: 微软雅黑,Microsoft YaHei;">$json</span>= iconv(<code class="Brush plain"><span style="font-family: 微软雅黑,Microsoft YaHei;">);</span>

'GBK'

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

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

,

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

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

$response = trim($response,chr(239).chr(187).chr(191));<br>$response = json_decode($response, true);<code><br><code><code class="Brush plain">

$json = stripslashes($json);

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

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

<code><br>等多种方法 都不行

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

更多相关教程请访问 php编程从入门到精通全套视频教程<br>最后发现返回的response数据有bom头字符

<code>$response = trim($response,chr(239).chr(187).chr(191));$response = json_decode($response, true);<code><code>这样正常解开了<code><code><code>base64_decode出来的json数据有没有bom头字符 除了网上说的其它方法  也可以放到json在线编辑器中查看附:<code><strong>json_decode要求的字符串比较严格:</strong>(1)使用UTF-8编码(2)不能在最后元素有逗号(3)不能使用单引号(4)不能有r,t,如果有请替换<code>更多相关教程请访问 <a style="font-family: 微软雅黑,Microsoft YaHei; text-decoration: underline;" href="http://www.php.cn/course/list/29.html" target="_blank">php编程从入门到精通全套视频教程</a>
声明
本文转载于: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)实现databasequerycachingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandredececonnection.4 limitsclection.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

databasequeryOptimizationinphpinvolVolVOLVESEVERSEVERSTRATEMIESOENHANCEPERANCE.1)SELECTONLYNLYNESSERSAYCOLUMNSTORMONTOUMTOUNSOUDSATATATATATATATATATATRANSFER.3)

简单指南:带有PHP脚本的电子邮件发送简单指南:带有PHP脚本的电子邮件发送May 12, 2025 am 12:02 AM

phpisusedforsenderemailsduetoitsbuilt-inmail()函数andsupportiveLibrariesLikePhpMailerandSwiftMailer.1)usethemail()functionforbasicemails,butithasimails.2)butithasimimitations.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,增强量产生性,可验证性和Maintainability.itallowspasspassingDepentenciesLikEdenceSeconnectionSeconnectionStoclasseconnectionStoclasseSasasasasareTers,interitationApertatingAeseritatingEaseTestingEasingEaseTeStingEasingAndScalability。

提高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

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具