c# Lambda-Hashtable元素添加至string[]

public void AjaxGetListByPage()
 {
     string[] InParameter = new string[] { };
     try
            {
                Hashtable ht = JsonConvert.DeserializeObject<Hashtable>(GetParam("obj"));
                if (ht.Count > 0)
                {
                    string[] filteredItems = ht.Cast<DictionaryEntry>()
                        .Where(x => x.Value.ToString() != "all")
                        .Select(x => string.Format(" and {0}='{1}'", x.Key, x.Value))
                        .ToArray();

                    InParameter = new string[] { "1=1" }
                    .Concat(filteredItems)
                        .ToArray();
                }
                int pageIndex = Convert.ToInt32(GetParam("pageSize")) * (Convert.ToInt32(GetParam("pageIndex")) - 1) + 1;
                int pageSize = Convert.ToInt32(GetParam("pageSize")) * Convert.ToInt32(GetParam("pageIndex"));
                int totalNum = bll.GetListOfCount(InParameter);
                DataTable dt = bll.GetList(pageIndex, pageSize, InParameter);
                Response.Write("{"
                               + "\"recordCount\":[{"
                               + "\"recordCount\":" + totalNum + "}]"
                               + ",\"recordInfo\":" + EnJson(dt)
                               + "}");
            }
     catch (Exception ex)
            {
                LogHelper.error(".....配置AjaxGetListByPage出错:" + ex.Message);
                Response.Write(EnJson(new { msg = "Fail" }));
            }
 }

EnJson:
命令空间:
using Newtonsoft.Json;

    /// 
    /// json转换
    /// 
    public static List<JsonConverter> JSON_CONVERTERS;


    /// 
    /// 生成 Json 的快捷方法
    /// 
    /// 
    /// 
    /// 
    /// 
    public static string EnJson(object obj)
    {
        return EnJson(obj, true);
    }

    /// 
    /// 生成 Json 的快捷方法
    /// 
    /// 
    /// 
    /// 
    /// 
    public static string EnJson(object obj, bool useConvertes)
    {
        JsonSerializerSettings jsonSettings = useConvertes
                                            ? new JsonSerializerSettings
                                            {
                                                NullValueHandling = NullValueHandling.Include,
                                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                                                Converters = JSON_CONVERTERS
                                            }
                                            : new JsonSerializerSettings
                                            {
                                                NullValueHandling = NullValueHandling.Include,
                                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                                            };
        // 解析成 Json
        var json = JsonConvert.SerializeObject(
            obj,
            // 判断是否需要格式化输出 Json
            Newtonsoft.Json.Formatting.Indented,
            jsonSettings
        );
        return json;
    }

你可能感兴趣的:(C#,Lambda,c#,开发语言)