开发者

url in json, jquery ajax response

开发者 https://www.devze.com 2022-12-21 12:30 出处:网络
{ \"imgsrc\":\"http:\\/\\/192.168.1.181\\/postcardthis\\/facebook\\/angel_wall.jpg\", \"message\":\"asdf\",
{
    "imgsrc":"http:\/\/192.168.1.181\/postcardthis\/facebook\/angel_wall.jpg",
    "message":"asdf",
    "friend":"Friend1",
    "error_message":""
}

This my JSON, here imgsrc location se开发者_StackOverflow社区ems difficult, two slashes. what to do to convert perfect URL?


Use jQuery.parseJSON( json ). It is available as of jQuery 1.4.

Description: Takes a well-formed JSON string and returns the resulting JavaScript object.

You should be able to do:

var myObj = jQuery.parseJSON('{"imgsrc":"http:\/\/192.168.1.181\/postcardthis\/facebook\/angel_wall.jpg","message":"asdf","friend":"Friend1","error_message":""}');
alert(myObj.imgsrc);


You have to eval your JSON string:

var js = eval(json_string);

Then, the imgsrc property in js will have your URL:

js.imgsrc;

0

精彩评论

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

关注公众号