开发者

Strange characters in Ajax response

I'm getting an Ajax response from a web service, and I'm not sure what the characters are. I need to convert them to their ASCII/UTF-8 equivalent but I don't know where to start.

An example of some of the characters are:

\x3d1
\x26pf
\x3dp
\x26s
\x3dpsy
\x26

The raw JSON response is from Google Suggest:

{e:"-5vsTZHOF8yo8QPK1YisAQ",c:1,u:"http://www.google.co.uk/s?hl\x3den\x26pq\x3dbbc\x26xhr\x3dt\x26q\x3dc\x26cp\x3d1\x26pf\x3dp\x26sclient\x3dpsy\x26source\x3dhp\x26aq\x3d\x26aqi\x开发者_如何学Python3d\x26aql\x3d\x26oq\x3d\x26pbx\x3d1\x26bav\x3don.2,or.r_gc.r_pw.\x26fp\x3d10b19ece71d55c8f\x26biw\x3d1280\x26bih\x3d554\x26tch\x3d1\x26ech\x3d1\x26psi\x3dv5vsTd78IMKvhQez9fCmCA.1307352340620.1",d:"[\x22c\x22,[[\x22c\\u003Cb\\u003Eurrys\\u003C\\/b\\u003E\x22,0,\x220\x22],[\x22c\\u003Cb\\u003Eomet\\u003C\\/b\\u003E\x22,0,\x221\x22],[\x22c\\u003Cb\\u003Ebbc\\u003C\\/b\\u003E\x22,0,\x222\x22],[\x22c\\u003Cb\\u003Eineworld\\u003C\\/b\\u003E\x22,0,\x223\x22],[\x22c\\u003Cb\\u003Earphone warehouse\\u003C\\/b\\u003E\x22,0,\x224\x22]],{j:1}]"}/*""*/{e:"-5vsTZHOF8yo8QPK1YisAQ",c:0,u:"http://www.google.co.uk/s?hl\x3den\x26pq\x3dbbc\x26xhr\x3dt\x26q\x3dc\x26cp\x3d1\x26pf\x3dp\x26sclient\x3dpsy\x26source\x3dhp\x26aq\x3d\x26aqi\x3d\x26aql\x3d\x26oq\x3d\x26pbx\x3d1\x26bav\x3don.2,or.r_gc.r_pw.\x26fp\x3d10b19ece71d55c8f\x26biw\x3d1280\x26bih\x3d554\x26tch\x3d1\x26ech\x3d1\x26psi\x3dv5vsTd78IMKvhQez9fCmCA.1307352340620.1",d:""}/*""*/


That looks like URL encoded characters. Normally you don't need to convert anything. For example if you get the following string from an AJAX call:

var x = '\x3d1\x26pf\x3dp\x26s\x3dpsy\x26';

if you try to print it:

alert(x);

it should display the correct value:

=1&pf=p&s=psy&


I think you should try this function utf8_decode

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜