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);