我自己写的html码如下:
<img id="BTImg" src="" width="623px" height="420px" style="z-index:1; position:absolute; margin:1px 0 0 0px; ">
JS代码:var GetBTImg = function(){
$.ajax({
url:'http://news.guet.cn/bcapi.asmx/next',
type: 'POST',
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: "",
error: function(json){
},
success: function(json){
var jsonData = eval('('+json+')');
$('#BTImg').attr('src',jsonData.str);
}
});
};
后台数据:<string xmlns="http://tempuri.org/">
{"str":"http://news.guet.edu.cn/BeautyAPI/image/15550.jpg"}
</string>
<img id="BTImg" src="" width="623px" height="420px" style="z-index:1; position:absolute; margin:1px 0 0 0px; ">
JS代码:var GetBTImg = function(){
$.ajax({
url:'http://news.guet.cn/bcapi.asmx/next',
type: 'POST',
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: "",
error: function(json){
},
success: function(json){
var jsonData = eval('('+json+')');
$('#BTImg').attr('src',jsonData.str);
}
});
};
后台数据:<string xmlns="http://tempuri.org/">
{"str":"http://news.guet.edu.cn/BeautyAPI/image/15550.jpg"}
</string>
就可以实现了
[{"str":"http://news.guet.edu.cn/BeautyAPI/image/08120.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08100.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08020.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08030.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08040.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08060.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08070.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08080.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08090.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/00000.jpg"}]
</string>获取的时候跟获取单张图片有什么区别?
//alert("Ddf");
$.ajax({
url:"http://news.guet.cn/bcapi.asmx/next",
error: function(){
},
success:function(data){
var s=$(data).find("string").text();
alert(s);
var te=strToJson(s);
alert(te.str);
$("#BTImg").attr("src",te.str);
}
});
};这样获取数据,就是提取str里面的地址,这个是一张图片的,如果里面有多张图片,比如
<string xmlns="http://tempuri.org/">
[{"str":"http://news.guet.edu.cn/BeautyAPI/image/08120.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08100.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08020.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08030.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08040.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08060.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08070.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08080.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/08090.jpg"},{"str":"http://news.guet.edu.cn/BeautyAPI/image/00000.jpg"}]
</string>
那么我该怎么提取呢?