Question

I'm requesting packets from a Server that I have no control over and they have no interest in any issues developers might have.

I would love to use the built in json_decode for PHP because of the speed, but I'm using a PHP based decoder from http://mike.teczno.com/json.html, and it can be extremely slow on packets with 40,000+ records.

This is the JSON after I've received it from the server and stripped the slashes (stripslashes()):

{
"results": {
    "localPlayers": {
        "friends": [
            {
                "name": "Player Name 1",
                "friend_name": "Friend Name 1",
                "level": "3"
            },
            {
                "name": ""PlayerName2"",
                "friend_name": "",
                "level": "3"
            },
            {
                "name": "Pl/\yer Name 3",
                "friend_name": "Friend Name 3",
                "level": "3"
            },
            {
                "name": "Player Name 4",
                "friend_name": "Friend "Name4"",
                "level": "4"
            }
        ]
    }
}
}

It should be:

{
"results": {
    "localPlayers": {
        "friends": [
            {
                "name": "Player Name 1",
                "friend_name": "Friend Name 1",
                "level": "3"
            },
            {
                "name": "\"PlayerName2\"",
                "friend_name": "",
                "level": "3"
            },
            {
                "name": "Pl/\\yer Name 3",
                "friend_name": "Friend Name 3",
                "level": "3"
            },
            {
                "name": "Player Name 4",
                "friend_name": "Friend \"Name4\"",
                "level": "4"
            }
        ]
    }
}
}

I've tried different things and searched all over for an alternate PHP extension that might handle "lazy" JSON. I think I've melted my brain by looking at all of the JSON offspring that are out there (in case this was normal to one or another), but can't seem to find anything that fits.

It would be nice to not have to hand edit the packets and use the speed of the built in PHP json decoder, but getting accurate info is more important and utilizing the Services_JSON has been my only answer.

Also, is the reason that Services_JSON is able to decode due to a bug in that decoder or in the JSON produced?

I'm hoping someone sees these "malformed" JSON packets and recognizes them.

Thank you.

Edit:

My apologies, here is the packet from the server before stripslashes:

I was using the stripslashes originally for the Apostrophes. :(

    {
   "results":{
      "localPlayers":{
         "friends":[
            {
               "name":"Player\'s Name 1",
               "friend_name":"Friend Name 1",
               "level":"3"
            },
            {
               "name":""PlayerName2"",
               "friend_name":"",
               "level":"3"
            },
            {
               "name":"Pl/\yer Name 3",
               "friend_name":"Friend Name 3",
               "level":"3"
            },
            {
               "name":"Player Name 4",
               "friend_name":"Friend "Name4"",
               "level":"4"
            }
         ]
      }
   }
}
Was it helpful?

Solution

Can you check if you are not using functions in any form in your code

stripslashes()
str_replace()

Check if you can use [JSON_UNESCAPED_SLASHES()][1] Available since PHP 5.4

In php.ini set magic_quotes_gpc = Off but this feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top