json_decode()返回空问题 [英] json_decode() returns null issues
问题描述
我的JSON有问题.它可以在PHP 5.3中正确返回(因此我不能使用json_last_error()),并且在我将字符串显式复制到json_decode(json_decode('{...}')中时成功返回.结果作为变量,我正在使用php 5.2,这就是我需要的.
I've an issue with my JSON. It works returns correctly in PHP 5.3 (so I can't use json_last_error()), and it returns successfully when I copy string explicitly into json_decode (json_decode('{...}'). It only returns null in when I pass the result as a variable and I'm using php 5.2, which is what I need it for.
输出来自PHPUnit中的JSON记录:
The output comes from JSON logging in PHPUnit:
[
{
"event": "suiteStart",
"suite": "",
"tests": 2
},
{
"event": "suiteStart",
"suite": "TagTestCase",
"tests": 2
},
{
"event": "test",
"suite": "TagTestCase",
"test": "TagTestCase::test_it",
"status": "fail",
"time": 0.00248718261719,
"trace": [
{
"file": "\/UnitTest\/PHPUnit.php",
"line": 98,
"function": "run",
"class": "PHPUnit_Framework_TestSuite",
"type": "->",
"args": [
{
}
]
},
{
"file": "\/UnitTest\/PHPUnit.php",
"line": 116,
"function": "run",
"class": "PHPUnit",
"type": "->",
"args": [
]
},
{
"file": "\/UnitTest\/PHPUnit.php",
"line": 212,
"function": "__tostring",
"class": "PHPUnit",
"type": "->",
"args": [
]
}
],
"message": "false assertionzzzzz.\nFailed asserting that <boolean:false> is true."
},
{
"event": "test",
"suite": "TagTestCase",
"test": "TagTestCase::test_two",
"status": "pass",
"time": 0.00182914733887,
"trace": [
],
"message": ""
}
]
这些是我一直在探索的路径-也许您是一个更好的探索者. 可能有帮助的三种路径:
These are the paths, I've been exploring - maybe you are a better explorer.. Three possible paths that could help:
- php 5.2和5.3中的json_decode()有何不同?他们做了什么改变?
- 其他人使用PHPUnit中的JSON及其解析方式.
- 将其包含在变量中与将其打印到屏幕并将其复制到json_decode()相比会发生什么变化
任何帮助将不胜感激(!).
Any help would be greatly(!) appreciated.
谢谢! 马特
推荐答案
多么糟糕的调试会话..好消息是..我知道了..
What a HORRENDOUS debug session.. well there's good news.. I figured it out..
我开始使用AJAX进行查看,并使用Firebug对其进行记录...结果证明json_decode(或顺便说说是eval)无法处理"
,这就是PHPUnit发送回去的内容(快来塞巴斯蒂安!),所以解决它:
I started looking at it using AJAX and logging it with Firebug... and it turns out json_decode (or eval by the way) cannot handle "
, which is what PHPUnit sends back (Come on Sebastian!), so to fix it:
$json = str_replace('"', '"', $json);
现在我以为他们是一样的..也许有人可以启发我..
Now I thought they were the same.. maybe someone can enlighten me..
这篇关于json_decode()返回空问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!