我有JSON数据的这个文件:
https://suggest.autocompleteapi.com/ap7d7hg5jezr/drg121016?prefix=pe&size=10
我想在jQUERY中使用非常简单的脚本来解析这些数据,
通过jQUERY到HTML网页到这样的ul风格:
<ul>
<li>K704 Alkoholové zlyhávanie pečene</li>
<li>K741 Skleróza pečene</li>
........
.......
</ul>
非常感谢你的时间
答案 0 :(得分:0)
您可以尝试以下内容:
//if the data is one string from ajax response,
//you have to parse the string to json object first
//let yourData = JSON.parse(ajax_response);
let yourData = {'suggestion':[
{'value':'K704 Alkoholové zlyhávanie pečene'},
{'value':'K718 Toxická choroba pečene s inými poruchami pečene'},
{'value':'K718 Toxická choroba pečene s inými poruchami pečene'}
]
}
let ulPlacedAt = $('body'); //you can change it to other object you like
let ulBody = '';
yourData['suggestion'].forEach(function(item) {
ulBody += '<li>'+item['value'] + '</li>';
}
)
ulBody = '<ul>' + ulBody + '</ul>';
ulPlacedAt.append(ulBody);
答案 1 :(得分:0)
我会在寻求SO帮助之前先研究一切。这可以通过使用.getJSON
$.getJSON("https://suggest.autocompleteapi.com/ap7d7hg5jezr/drg121016?prefix=pe&size=10", function(result) {
var data = result.suggestions;
for (var i = 0; i < data.length; i++) {
$('.lists').append('<li>' + data[i].value + '</li>');
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="lists">
</ul>
&#13;