I wrote a sample html which retrieves the JSON from servlet and displays. But only the thing is i want to know how to iterate the returned JSON response using jQuery. Currently i'm iteratng using javascript for loop.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="javascript/jquery-1.4.4.js"></script>
<!-- Here we need to load the trends on page load starts -->
<script>
$(document).ready(function(){
// now load the results from servlet
// $("#trends").load("ReadRSSTrendsUsingServlet");
// now get the result and retrieve each entry
$.getJSON("ReadRSSTrendsUsingServlet",function(data){
// alert(data.trends[2]);
for(var i=0;i<data.trends.length;i++)
{
$("#trends").append(data.trends[i]).append("<br>");
}
});
});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div id="trends">
<!-- Here is the data to be loaded -->
</div>
</body>
</html>
After that it displaying the list of JSON values. My JSON object is like below
{"trends":["test1","test2","test3","test4","test5"]}
What i want is to know the equivalent of jQuery for below steps
for(var i=0;i<data.trends.length;i++)
{
$("#trends").append(data.trends[i]).append("<br>");
}
$("#trends").append()after the loop. Or for this particular situation, use the.join()solution that was given.