2013年7月25日星期四

jsonp parsing problem

 This post last edited by the Rico_ on 2013-07-22 23:12:36 project called Sina microblogging api returns jsonp data analysis does not, to the younger heroes look, thanks

Generally, we get to the server returns a json are similar to these. For example {"urls": [
{"result": true, "url_short": "http://t.cn/h5FGy", "url_long": "http://www.cnblogs.com", " type ": 0}
]} a complete json data. Name-value pairs correspondence, clearly structured array object


but now I get to was this. (I obtained through the alert)
jQuery18308495466143358499_1374500715357 ({"statuses": [{"created_at": "Mon Jul 22 21:31:40 +0800 2013", "id": "3602976080238037", " ; mid ":" 3602976080238037 "," idstr ":" 3602976080238037 "," text ":" \ u4f60 \ u4e0d \ u662f \ u6211 \ u7684 \ u795e \ u5bf9 \ u624b @ \ u6012 \ u543c \ u7684 \ u571f \ u5305 \ u5b50 \ u4f60 \ u662f \ u6211 \ u7684 \ u5c0f \ u4f19 \ u4f34 \ u548c \ u732a \ u961f \ u53cb [\ u9177] \ u6211 \ u5728: http: \ / \ / t.cn \ / zQZVsKR "," source ":"... behind omitted


But now I get to this is the expectation
{"statuses": [{"created_at": "Mon Jul 22 21:27:00 +0800 2013", "id": "3602974909414937", "mid" ;: "3602974909414937", "idstr": "3602974909414937", "text": "\ u4e0b \ u6b21 \ u518d \ u6765 \ u5e0c \ u671b \ u6709 \ u4f60 @ \ u8c22 \ u6f47x-x \ u6211 \ u5728 \ u8fd9 \ u91cc: http: \ / \ / t.cn \ / zHecOsL "," source ":". . . Behind omitted

That is more out front jQuery18308495466143358499_1374500715357
so getdata.data [0] Get to the j
Why? Then I checked the Internet
displayed as follows:
$. ajax ({
type: "get",
async: false,
url: "ajax.ashx",
dataType: "jsonp",
jsonp: "callbackparam", / / ​​passed to the request handler or page to get jsonp callback function name parameter name (default: callback)
jsonpCallback: "success_jsonpCallback", / / ​​custom jsonp callback function name, the default is auto-generated random jQuery function name

Indeed, I have the page references jquery1.8.3
But now the question is how do I get my expectations for it? (That is in front and then remove jQuery18308495466143358499_1374500715357 parsed) but certainly one of the most simple and crude way is to use js string manipulation functions removed, but there are not always returned to the fixed prefix that this section is repeated again and again to change words The. I ask for a correct approach. Or heroes are how to parse jsonp data it?


In this, the younger brother jQuery18308495466143358499_1374500715357 ask why there should be how to resolve it over his back? See full return json http://pan.baidu.com/share/link?shareid=2950801806 & ; uk = 2416608530




my code
 $ (document). ready (function () {

$. Ajax ({
url: "https://api. ****. json ? *** ",
type: "GET",
dataType: "jsonp",
cache: false,
success: function (getdata) { alert (getdata); alert (getdata.data);
/ / Var mes_obj = ; eval ("(" + getdata.data + ")");
var str_statuses; str_statuses = getdata.data [0 ]; alert (str_statuses);
}
}); });


sequentially eject
[object object]
[Full json (see link)]
[j]


Now my question is how to properly parse jsonp?
callback callback seems to have what? That is how to use? I am now using jquery parsing.


Finally, I read this article, as he did, the results did not make like his results.


------ Solution ------------------------------------ --------
jQuery18308495466143358499_1374500715357 is automatically generated function name jq
That is what you get is of the form
func ({"statuses": data volume})
Such a js statement jq do not know why he did not go to perform. Where might you write the wrong
alternative approach is
dataType: "jsonp",
jsonp: "callbackparam" / / that specify a callback function name, so it will not automatically generated jq
So the returned data should become
callbackparam ({"statuses": data volume})
in the kind of the
eval to execute it and then you look you can get a json object
The jq this thing done this, I do not know why he did not do
he does not do, only do their own

------ Solution ------------------------------------ --------
 This post last edited by the showbo on 2013-07-24 14:12:26 specify a callback function on the line. . As to why the returned data Sina data plus the name of the callback function is not clear. Did not find instructions
 

 

没有评论:

发表评论