Viewed   97 times

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.

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": ""
    }
]

EDIT: These are the paths, I've been exploring - maybe you are a better explorer.. Three possible paths that could help:

  • What is different about json_decode() in php 5.2 then 5.3? what did they change?
  • Someone else using JSON from PHPUnit, and how they parse it.
  • What changes when you have it in a variable vs. printing it to screen and copying it into json_decode()

Any help would be greatly(!) appreciated.

Thanks! Matt

 Answers

3

What a HORRENDOUS debug session.. well there's good news.. I figured it out..

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 &quot;, which is what PHPUnit sends back (Come on Sebastian!), so to fix it:

$json = str_replace('&quot;', '"', $json);

Now I thought they were the same.. maybe someone can enlighten me..

Friday, December 23, 2022
5

EDIT 1: This may also have to do with the fact that getAllPersoonData and getAllLessenData have the same input signature, which means that, for document literal style web services, the endpoint won't be able to distinguish what kind of request you're actually making. Try passing two different element names.

EDIT 2: Also, giving these messages different signatures would allow you to put getPersoonID within the type definition so that you only have one message part. Right now, if you look in Customer.wsdl you have:

<wsdl:message name="getPersoonIDCustomerID">
    <wsdl:part name="body" element="ns:UserCredentials"/>
    <wsdl:part name="getPersoonID" type="xs:int"/>
</wsdl:message>

You should not have more than one part in a document-literal message.

EDIT 3: If you don't want to define a new element for each function that you have, then you would have to switch to RPC literal, which wraps the request in the wsdl:operation name. If this would fix everything except .NET, then you could try my SO post on coaxing .NET into reading RPC-literal web services.

Saturday, August 13, 2022
 
1

Your request looks fine, it should work. Did you set up services.wsdl with your EWS server address? (see http://ewswrapper.lafiel.net/basic-info/working-with-ewswrapper/ for some more info)

Try looking at the actual call before it is send and the response before it is interpreted. To do so in NTMLSoapClinet.php print $request at the top of __doRequest() function and end script execution (ie. die()) and then try printing $response befor it is returned in __doRequest() function and end script execution. This should give you some more insight on what's going on.

Friday, December 9, 2022
1
$j = '{"j": 1 ] }';

json_decode($j);

var_dump(json_last_error() === JSON_ERROR_STATE_MISMATCH); // true

How I found it: just checked the source code :-)

Sunday, December 11, 2022
 
4

you can use it like this, in JSON format when you evaluate false value it will give you blank, and when you evaluate true it will give you 1.

$str = '[{"clientId":"17295c59-4373-655a-1141-994aec1779dc","channel":"/meta/connect","connectionType":"long-polling","ext":{"fm.ack":false,"fm.sessionId":"22b0bdcf-4a35-62fc-3764-db4caeece44b"},"id":"5"}]';

$arr = json_decode($str,true);

if($arr[0]['ext']['fm.ack'])    // suggested by **mario**
{
    echo "true";    
}
else {
    echo "false";   
}
Thursday, October 6, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :