zoukankan      html  css  js  c++  java
  • .net获取数据后特殊字符串处理

    1.数据全部加密的写法:

    dt = ds.Tables[0];

                        foreach (DataRow row in dt.Rows)

                        {

                            for (int i = 0; i < dt.Columns.Count; i++)

                            {

                                if (row[i].ToString() != "")

                                {

                                    row[i] = Server.UrlEncode(row[i].ToString()).Replace("+", "%20");

                                }

                            }

                        }

    Js接收数据后解密:

    var resultVal = JSON.parse(result.SuccessMsg);

    for (var i = 0; i < resultVal.rows.length; i++) {

                        for (var k = 0; k < Object.getOwnPropertyNames(resultVal.rows[i]).length; k++) {

                            resultVal.rows[i][Object.getOwnPropertyNames(resultVal.rows[i])[k]] = decodeURIComponent(resultVal.rows[i][Object.getOwnPropertyNames(resultVal.rows[i])[k]]);

                        }

                    }

    2.数据单个加密的写法:

    DataSet ds2 = DbHelperOra.Query(sql, paras);

    DataTable dt = new DataTable();

    if (ds.Tables.Count > 0)

    {

      dt = ds.Tables[0];

      foreach (DataRow row in dt.Rows)

      {

        row["CUST_NAME"] = Server.UrlEncode(row["CUST_NAME"].ToString()).Replace("+", "%20");

        row["PRODUCT_NAME"] = Server.UrlEncode(row["PRODUCT_NAME"].ToString()).Replace("+", "%20");

      }

    }

    string json = new DTToJson().DataTableToJson(dt, ds2.Tables[0].Rows.Count);

    Js接收数据后解密:

    var resultVal = JSON.parse(result.SuccessMsg);

    for (var i = 0; i < resultVal.rows.length; i++) {

         resultVal.rows[i].CUST_NAME = decodeURIComponent(resultVal.rows[i].CUST_NAME);

         resultVal.rows[i].PRODUCT_NAME = decodeURIComponent(resultVal.rows[i].PRODUCT_NAME);

    }

    $("#gdView1").datagrid('loadData', resultVal);

  • 相关阅读:
    MongoDB数据库性能分析(转)
    C++中拷贝构造函数
    C++中的继承和组合区别使用
    几种调用约定
    动态规划(基础篇)
    C++中的三种继承public,protected,private
    STl中的排序算法
    STL中的常用算法
    C++初始化函数列表
    设计模式之装饰模式(Decorator)
  • 原文地址:https://www.cnblogs.com/guangfangxiaokeai/p/12517927.html
Copyright © 2011-2022 走看看