Assume the JSON returned is
{"2010143545":{"info":[开发者_如何学C1,"soccer"]},
"2010143547":{"info":[0,"Basketball"]}
}
How do I use jQuery to render the array on ASP.NET page? More precisely, what kind of HTML template do I need to set to stuff the JSON with jQuery?
Thank you.
HTML for a result div:
<div id="myDiv">Results here</div>
And the JS. I'll try to make it clear how to use it.
$.get("webservice.asmx?id=555", function(data){
var str = "";
for(var i = 0; i < data.length; i++){
var number = data[i]; // When i=0, this is "2010143545"
var infoName = data[i].info[1]; // When i=0, this is "soccer"
// Example of rendering
str += "<p>The number " +number+ " holds the name " +infoName+ "</p>";
}
$("#myDiv").html(str);
});
精彩评论