I am trying to decode the Google Dictionary API JSON response with PHP, but I am running into an issue where I cannot seem to parse the response (json_decode
re
Google returns the result in the form of a function call. If you want to get rid of that you can do: So you have to strip that part off:
$file = substr($file, 2, -10);
Furthermore all the hex characters cause a mess. I don't know the best way of dealing with these (they should be converted to their character, but how to go about that easily requires thought). For testing purposes you can just strip them (to see that it then works). Try:
$file = preg_replace("/\\\x[0-9a-f]{2}/", "", $file);
So in the end you have:
For converting the characters as needed, I suppose you could use preg_replace_callback, but I don't like that function, specially when the data comes from a remote source. Simpler may be to simply have a static mapping, eg:
$from = array("\x3d", "\x22", ...);
$to = array("=", "\"", ...);
$file = str_replace($from, $to, $file);