1

I have a curl request which returns a json string. The results looks like, and can have any value of escaped hex unicodes:

{ "title" : "20\x2f20" }//curl result example

I have tried everything to decode this results escaped unicode into its ascii character. I ultimately want to convert to a valid json object:

{ "title" : "20/20" }

However nothing seems to work...

$foo='{ "title" : "20\x2f20" }';
$foobar = addcslashes($foo, '"');
echo htmlentities($foobar,NULL,'UTF-8');
echo htmlentities($foo);
echo json_encode($foo);
echo json_encode($foo,JSON_UNESCAPED_SLASHES);
echo json_encode($foo,JSON_UNESCAPED_UNICODE);
//none of the above produces the desired result: { "title" : "20/20" }

Any help would be appreciated.

cube
  • 1,774
  • 4
  • 23
  • 33
  • 3
    That's not JSON encoding, but a C escape. See [`stripcslashes`](http://php.net/stripcslashes). – mario Feb 17 '15 at 01:43
  • Possible duplicate of [simplejson.loads() get Invalid \escape: 'x'](http://stackoverflow.com/questions/4296041/simplejson-loads-get-invalid-escape-x) – trincot Jan 29 '16 at 13:11

0 Answers0