PHP: Handling 'JSONP' output vs 'JSON', and its parsing?

后端 未结 3 856
遇见更好的自我
遇见更好的自我 2021-01-18 13:49

I am having a problem parsing \'jsonp\' request with php\'s json_decode function.

My questions is

a. What is the u

3条回答
  •  孤独总比滥情好
    2021-01-18 14:21

    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.

提交回复
热议问题