我使用jQuery .load()函数从服务器加载结果,并将其附加到我的html中:
$("#content").load('Get/Information?class=Arts&min=1',
function (responseText, textStatus, XMLHttpRequest) {
console.log(responseText);
// parseJSON(responseText);
});在我的控制器中,我尝试将我的锯齿数组从模型转换为json对象,然后将它发送给客户机:
public JsonResult GetInformation(string class, int min){
var stdObj = new Student();
string[][] information = stdObj.GetInformation(class, min);
return Json(information, JsonRequestBehavior.AllowGet);
}在此之后,当我通过console.log(responseText);检查响应时,我有一个类似于jSon的字符串,格式如下:
[
["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]我不确定这是否是一个正确的jSon,从我所了解的jSon名称中看:值对,但这里只有值,考虑到这一点,我如何读取这个字符串/数组并以下列方式打印:
--这只是我需要如何处理它的一种表示(伪代码):
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>');
}发布于 2013-07-01 11:14:23
使用var dataArray = jQuery.parseJSON(response);
发布于 2013-07-01 11:16:51
如果您的响应数组是
myArray =
[
["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"],
]您可以使用
for(int i=0; i<myArray.length();i++)
{
$("#content").html('<h1>'+myArray[i][0]+'</h1>'+'<p>'+myArray[i][1]+'</p>'+'<span>'+myArray[i][2]+'</span>').slideDown('slow');
}演示:http://jsfiddle.net/KX596/1/
发布于 2013-07-01 11:14:04
您需要使用getJSON()
$.getJSON('Get/Information?class=Arts&min=1', function (response) {
$.each(response, function(idx, rec){
$("#content").append('<h1>'+rec.Id+'</h1>'+'<p>'rec.Title+'</p>'+'<span>'+rec.url+'</span>').slideDown('slow');
})
});https://stackoverflow.com/questions/17403103
复制相似问题