Maven Maven - 1 year ago 140
Javascript Question

How to read JSON array in jQuery

I am using

function to load the results from server and append it in my html:

function (responseText, textStatus, XMLHttpRequest) {
// parseJSON(responseText);

In my controller I tried converting my jagged array from the model into a json object and then send it to the client:

public JsonResult GetInformation(string class, int min){
var stdObj = new Student();
string[][] information = stdObj.GetInformation(class, min);
return Json(information, JsonRequestBehavior.AllowGet);

And after this when I check the response through

I have a jSon like string in the following format:

["92"," Title-2",""],
["90"," Title-3",""],
["89"," Title-4",""],
["89"," Title-5",""],

I am not sure if this a proper jSon, as from what I learn jSon is in name: value pairs, but here there are only values, considering this how can I read this string/array and print in following manner:

This just a representation(pseudo code) of how I required it to be handled:

for(int 1=0; i<response.length();i++){
// $("#content").html('<h1>39</h1>'+'<p>Title-1</p>'+'<span></span>');

Answer Source

Use var dataArray = jQuery.parseJSON(response);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download