zoukankan      html  css  js  c++  java
  • Asp.net mvc 3 JSONResult return array

    publicclassArrayJsonResult:System.Web.Mvc.JsonResult
    {
       
    publicoverridevoidExecuteResult(ControllerContext context)
       
    {
           
    if(context ==null)
           
    {
               
    thrownewArgumentNullException("context");
           
    }
           
    if(JsonRequestBehavior==JsonRequestBehavior.DenyGet&&
               
    String.Equals(context.HttpContext.Request.HttpMethod,"GET",StringComparison.OrdinalIgnoreCase))
           
    {
               
    thrownewInvalidOperationException("JsonRequest_GetNotAllowed");
           
    }

           
    HttpResponseBase response = context.HttpContext.Response;

           
    if(!String.IsNullOrEmpty(ContentType))
           
    {
                response
    .ContentType=ContentType;
           
    }
           
    else
           
    {
                response
    .ContentType="application/json";
           
    }
           
    if(ContentEncoding!=null)
           
    {
                response
    .ContentEncoding=ContentEncoding;
           
    }
           
    if(Data!=null)
           
    {
               
    StringWriter sw =newStringWriter();
                sw
    .Write("[");
               
    try
               
    {
                   
    var collection =DataasIEnumerable<String>;
                   
    int countLessOne = collection.Count()-1;
                   
    for(int i =0; i < countLessOne; i++)
                   
    {
                        sw
    .Write(collection.ElementAt(i));
                        sw
    .Write(",");
                   
    }
                    sw
    .Write(collection.ElementAt(countLessOne));
               
    }
               
    catch(Exception)
               
    {
                   
    //data was not a collection
               
    }

                sw
    .Write("]");
                response
    .Write(sw.ToString());
           
    }
       
    }
  • 相关阅读:
    Pixel XL编译和烧录Android 8.0
    公式编辑器CVE-2018-0798样本分析
    CVE-2021-33739 EOP漏洞分析
    Firefox 设置 Burpsuite 代理抓取本地数据包
    前端ECharts框架绘制各种图形
    c 除法反汇编算法
    IDA sig签名批量脚本
    从零构建自己的远控•客户端设计面向对象(13)
    从零构建自己的远控•AES加解密Demo(12)
    从零构建自己的远控•图像切割算法构思(11)
  • 原文地址:https://www.cnblogs.com/webglcn/p/2661444.html
Copyright © 2011-2022 走看看