本文介绍了如何在ASP.NET webform方法中将客户验证消息作为json返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 catch (Exception ex)
            {
			 throw ex;

            }
            finally
            {
                con.Close();
            }


            ArrayList a = new ArrayList();
            a.Add(reportList);
            a.Add(p);
 if (reportList.Count()  != 0)
            {
 return JsonConvert.SerializeObject(a);
            }
			else{

			return // "custom message records not found"
}





我尝试过:





What I have tried:

 catch (Exception ex)
            {
			 throw ex;

            }
            finally
            {
                con.Close();
            }


            ArrayList a = new ArrayList();
            a.Add(reportList);
            a.Add(p);
 if (reportList.Count()  != 0)
            {
 return JsonConvert.SerializeObject(a);
            }
			else{

			return // "custom message records not found"
}

推荐答案

public class ValidationMessage
{
    public int success { get; set; }
    public string message { get; set; }
}
Usage:

var valMessage = "{\"success\":1,\"message\":\"successfully created.\"}";
return JsonConvert.DeserializeObject<ValidationMessage>(valMessage);


if (reportList.Count()  != 0)
            {
            a.Add("success");
              a.Add(reportList);
            a.Add(p);
            }
			else {
            a.Add("failure");
              a.Add("Your custom message");
        }
             return JsonConvert.SerializeObject(a);


这篇关于如何在ASP.NET webform方法中将客户验证消息作为json返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:49
查看更多