Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert Json object output to Jquery array format
    text
    copied!<p>Below is the Json output i am getting on Client Side:</p> <pre><code>jsonp1363710839478({"Comment":[{"Author":"Plan_A","CommentText":"AI like hay almost as much as I like sun. Just joking","Title":"AMaking hay when the sun shines"},{"Author":"Plan_B","CommentText":"I like hay almost as much as I like sun. Just joking","Title":"Making hay when the sun shines"}]}); </code></pre> <p>How to convert this to the example below:</p> <pre><code>var sample= [ { Title: "The Red Violin", Author: "1998" }, { Title: "Eyes Wide Shut", Author: "1999" }, { Title: "The Inheritance", Author: "1976" } ]; </code></pre> <p>Below is my full code:</p> <p>Code behind:</p> <pre><code> [OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Json)] public CommentList GetComments() { Comments oComment1 = new Comments(); oComment1.Title = "AMaking hay when the sun shines"; oComment1.Author = "Plan_A"; oComment1.CommentText = "AI like hay almost as much as I like sun. Just joking"; Comments oComment2 = new Comments(); oComment2.Title = "Making hay when the sun shines"; oComment2.Author = "Plan_B"; oComment2.CommentText = "I like hay almost as much as I like sun. Just joking"; CommentList oCommentList = new CommentList(); oCommentList.Comment.Add(oComment1); oCommentList.Comment.Add(oComment2); return oCommentList; } </code></pre> <p>Client Call Jquery:</p> <pre><code> $('#CommentsButton').click(function () { $.getJSON('http://localhost:55679/RESTService.svc/GetComments?callback=?', function (data) { for (var i = 0; i &lt; data.Comment.length; i++) { alert(data.Comment[i].Author); } }); </code></pre> <p>I am new to Jquery so detail explanation/code would be appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload