如何使用jquery ajax解析json文件中的多级数组
解析多级json并获取所有数据。使用下面的代码,我只能从json文件中获得一个长描述。请帮忙如何使用jquery ajax解析json文件中的多级数组,jquery,ajax,json,Jquery,Ajax,Json,解析多级json并获取所有数据。使用下面的代码,我只能从json文件中获得一个长描述。请帮忙 <input type="button" value="Get and parse JSON" class="button" /> <br /> <span id="results"></span> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/
<input type="button" value="Get and parse JSON" class="button" />
<br />
<span id="results"></span>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('.button').click(function(){
$.ajax({
url: "http://devcda.bryant.com/bryant/en/us/CommonSearchHandler.ashx?type=17&blogcategories=",
dataType: "text",
success: function(data) {
var json = $.parseJSON(data);
$("#results").html('<a href="' + json.CurrentPage + '">' + json.ResultPayload[0].LongDescription + "</a>");
}
});
});
});
</script>
您可以使用for循环迭代
json.ResultPayload
$("#results").empty();
for(var i in json.ResultPayload){
$("#results").append('<a href="' + json.CurrentPage + '">'
+ json.ResultPayload[i].LongDescription + "</a>");
}
$(“#结果”).empty();
for(json.ResultPayload中的变量i){
$(“#结果”)。追加(”);
}
$("#results").empty();
for(var i in json.ResultPayload){
$("#results").append('<a href="' + json.CurrentPage + '">'
+ json.ResultPayload[i].LongDescription + "</a>");
}