I had a problem processing the jsonp request using the php function json_decode .
My questions
a. What is the jsonp callback function if I just turn it off, or I suppose to use it somehow.
b. How can I fix the syntax error received in jsonp format?
Below I have given the code and the answer that I get.
1. I am requesting a url sample with curl PHP
$url = 'https://ssl.domain.com/data/4564/d.jsonp'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); $feed = curl_exec($ch); curl_close($ch); echo $feed = gzdecode($feed);
2. Then I try to execute json_decode the output that produces error 4, which means JSON_SYNTAX_ERROR , the reason, in my opinion, is that the string type names in jsonp are not quoted. e.g. Categories , Name , Position , etc.
$json_feed = json_decode($feed); $error = json_last_error(); echo $error;
3. RAW 'jsonp' is inferred from the URL.
domain_jsonp_callback({ Categories:[ { Name:"Artifacts", Position:14, Count:70, ImageUrls:{ i100:"//s3-eu-west-1.amazonaws.com/s.domain.com/1.png", i120:"//s3-eu-west-1.amazonaws.com/s.domain.com/2.png", i140:"//s3-eu-west-1.amazonaws.com/s.domain.com/3.png", i180:"//s3-eu-west-1.amazonaws.com/s.domain.com/4.png", i220:"//s3-eu-west-1.amazonaws.com/s.domain.com/5.png", i280:"//s3-eu-west-1.amazonaws.com/s.domain.com/6.png" } } ] });