Asp.net mvc 3 ASP.NET MVC 3解析JSon对象并显示数据

Asp.net mvc 3 ASP.NET MVC 3解析JSon对象并显示数据,asp.net-mvc-3,Asp.net Mvc 3,我有一节课 public class ConversionResultModel { public string ProcessId { get; set; } public bool Result { get; set; } public string Message { get; set; } } 使用JSon将其发送到视图 public ActionResult UploadFile(IEnumera

我有一节课

public class ConversionResultModel
    {
        public string ProcessId { get; set; }
        public bool Result { get; set; }
        public string Message { get; set; }         
    }
使用JSon将其发送到视图

   public ActionResult UploadFile(IEnumerable<HttpPostedFileBase> clientUpload)
    {
        string destinationPath = "";
        JsonResult result = null;
        var fileModel = new ConversionResultModel();
        fileModel.ProcessId = "4558-95559-554";
        fileModel.Result = true;
        fileModel.Message = "test.pdf";
        result = Json(new { fileModel }, "text/plain");


        return result;
    }
我收到的JSon对象如下

{"fileModel":{"ProcessId":"4558-95559-554","Result":true,"Message":null,"SourceFile":null,"ConvertedFileName":"test.pdf","ConvertedFileSize":1233444,"DownloadUrl":"http://localhost:2008/download?path=4558-95559-554","DeleteUrl":"http://localhost:2008/download?path=4558-95559-554"}}


在您的情况下,我认为您返回了正确的JSON,但您的警报指向了错误的对象。尝试使用alert(obj.SomeProperty)而不是alert(e.obj)。e、 obj不存在,这可能就是为什么会出现“未定义”错误的原因。例如,警报(obj.fileModel.ProcessId);应该可以工作。

您不需要解析它。仅在ajax请求期间,然后使用接收到的数据对象(如实体),您就可以轻松访问任何属性:

var id = data.ProcessId;
无论如何,您可以使用解析JSON字符串:

var data = jQuery.parseJSON(stringData);
附言:

使用以下代码示例在ASP.NET MVC中将对象转换为JSON:

return this.Json(fileModel);

我曾尝试使用$.parseJSON(e.response)进行解析,但它不起作用。它做了什么或没有做什么?有错误吗?知道什么是未定义的吗?功能?你是在使用Firebug或Chrome中的开发者工具来帮助你吗?那是我的问题!我试图过度分析我的回答。我只需要给酒店打个电话!谢谢
return this.Json(fileModel);