I am having a problem parsing \'jsonp\' request with php\'s json_decode
function.
My questions is
a. What is the u
Not sure about it but i think names should also be quoted like this:
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"
}
}
]
});
PS: Probably "Categories" too :?
What is the use of call back function in 'jsonp', should i just trip that off, or am I suppose to use it in some manner. ?
JSON-P is really a JavaScript script that consists of a function call with an argument.
If you want to parse it in PHP, then yes, you need to strip it off. You also need to strip off the );
at the end.
b. How can I rectify the syntax error received in 'jsonp' format ?
You need to fix the data so it really is JSON. The data you have is a JavaScript literal, but it doesn't conform to the subset of JavaScript that matches JSON (e.g. property names are not strings but must be).
It would be better to get a real JSON resource form the source instead.
Callback function is for JS calls - it allows to use API's in AJAX manner, without taking care of same origin policy. When JSONP call is used in JS - browser just calls the callback function that needs to be defined on API client's side.
When you use JSONP inside PHP callback function is not needed at all. If server supports raw JSON type calls - use it, if not strip the callback function strings, in your case
$jsonData = json_decode(substr($feed, 22, -2));