jquery json
调用 服务器webservice返回的值是这样子:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="mytest/">{ "dd":[ { "f_id":"1","f_name":"王一"},
{ "f_id":"2","f_name":"王二"},
{ "f_id":"3","f_name":"王三·"}
]}</string>
接收
<script>
$(function(){
$('button').click(function(){
$.ajax({
url: "http://localhost/anserver/appws.asmx/GetUserList",
type: "POST",
data: {a:1,b:1},
dataType: 'text',
success: function(result) {
alert(result);
},
error: function(x, e) {
alert("错误");
}
});
});
});
</script>
怎么把xml里面的json值取出来
或者有什么方法直接得到json数据,不包括外面那层xml,前提是调用webservice
------解决方案--------------------function getJsonStr(xml){
if(!xml) return '';
xml = String(xml);
var start=xml.indexOf('{');
if(start==-1) return '';
var end = xml.lastIndexOf('}');
if(end <= start) return '';
return xml.substring(start,end+1);
}
不知道这个符合你得需求不