1
创建的字符串数组是如何通过带胡须的json字符串集合进行循环?
public JsonResult GetInvalidFilesAJAX(JQueryDataTableParamModel param)
{
string[] invalidFiles = new string[] { "one.xls", "two.xls", "three.xls" };
return Json(new
{
Status = "OK",
InvalidFiles = invalidFiles
});
}
的MVC和JavaScript应该循环并打印出每个字符串
$.ajax(
{
type: 'POST',
url: 'http://localhost:7000/ManualProcess/GetInvalidFilesAJAX',
success: function (response) {
if (response.Status == 'OK') {
//Use template to populate dialog with text of Tasks to validate
var results = {
invalidFiles: response.InvalidFiles,
};
var template = "<b>Invalid Files:</b> {{#invalidFiles}} Filename: {{invalidFiles.value}} <br />{{/invalidFiles}}";
var html = Mustache.to_html(template, results);
$('#divDialogModalErrors').html('ERROR: The following files have been deleted:');
$('#divDialogModalErrorFiles').html(html);
如何我指的是字符串数组中?上面的方式是不正确的。我发现的所有例子似乎都是为了当杰森系列有属性名称..在我的情况下,它只是一个关键值对(我猜?)
我不能得到下面的行工作..究竟应该放在'jsonString'位置? var data = JSON.parse(response.InvalidFiles); – punkouter 2013-05-08 19:05:17
@punkouter您收到的JSON字符串作为回应。如果它已经是一个JSON对象,那么就把'data = object'。你可以'console.log(response.InvalidFiles)'为我吗? – 2013-05-08 19:06:12
one.xls,two.xls,three.xls ..所以我想这是一个JavaScript数组,而不是一个JSON对象吗? – punkouter 2013-05-08 20:04:44