Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
82
rated 0 times [  89] [ 7]  / answers: 1 / hits: 50768  / 11 Years ago, mon, july 1, 2013, 12:00:00

I am using jQuery .load() function to load the results from server and append it in my html:



$(#content).load('Get/Information?class=Arts&min=1', 
function (responseText, textStatus, XMLHttpRequest) {
console.log(responseText);
// 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 console.log(responseText);
I have a jSon like string in the following format:



[
[93,Title-1,http://stackoverflow.com],
[92, Title-2,http://stackoverflow.com],
[90, Title-3,http://stackoverflow.com],
[89, Title-4,http://stackoverflow.com],
[89, Title-5,http://stackoverflow.com],
null,null,null,null,null]


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>'+i.Id+'</h1>'+'<p>'+i.Title+'</p>'+'<span>'+i.url+'</span>')
.slideDown('slow');
// $(#content).html('<h1>39</h1>'+'<p>Title-1</p>'+'<span>http://stackoverflow.com</span>');
}

More From » jquery

 Answers
27

Use var dataArray = jQuery.parseJSON(response);


[#77283] Saturday, June 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadap

Total Points: 101
Total Questions: 104
Total Answers: 98

Location: Mexico
Member since Sun, Jul 25, 2021
3 Years ago
;