zoukankan
html css js c++ java
dataset数据转换成json的格式(转)
/**/
///
<summary>
///
把dataset数据转换成json的格式
///
</summary>
///
<param name="ds">
dataset数据集
</param>
///
<returns>
json格式的字符串
</returns>
public
static
string
GetJsonByDataset(DataSet ds)
{
if
(ds
==
null
||
ds.Tables.Count
<=
0
||
ds.Tables[
0
].Rows.Count
<=
0
)
{
//
如果查询到的数据为空则返回标记ok:false
return
"
{\
"
ok\
"
:false}
"
;
}
StringBuilder sb
=
new
StringBuilder();
sb.Append(
"
{\
"
ok\
"
:true,
"
);
foreach
(DataTable dt
in
ds.Tables)
{
sb.Append(
string
.Format(
"
\
"
{
0
}
\
"
:[
"
,dt.TableName));
foreach
(DataRow dr
in
dt.Rows)
{
sb.Append(
"
{
"
);
for
(
int
i
=
0
; i
<
dr.Table.Columns.Count; i
++
)
{
sb.AppendFormat(
"
\
"
{
0
}
\
"
:\
"
{
1
}
\
"
,
"
, dr.Table.Columns[i].ColumnName.Replace(
"
\
""
,
"
\\\
""
).Replace(
"
\'
"
,
"
\\\'
"
), FieldTypeFilter.ObjToStr(dr[i]).Replace(
"
\
""
,
"
\\\
""
).Replace(
"
\'
"
,
"
\\\'
"
));
}
sb.Remove(sb.ToString().LastIndexOf(
'
,
'
),
1
);
sb.Append(
"
},
"
);
}
sb.Remove(sb.ToString().LastIndexOf(
'
,
'
),
1
);
sb.Append(
"
],
"
);
}
sb.Remove(sb.ToString().LastIndexOf(
'
,
'
),
1
);
sb.Append(
"
}
"
);
return
sb.ToString();
}
相应的jQuery读取json方式
$.getJSON(
"
page.aspx
"
,
{process:
'
getinfo
'
,idx:idx}
,
function
(json)
{
if
(json.ok
==
true
)
{
$(
"
#slGameType
"
).val(json.Table[
0
].GameType);
$(
"
#txtSelectName
"
).val(json.Table[
0
].SelectName);
$(
"
#txtmyName
"
).val(json.Table1[
0
].myName);
$(
"
#txtmyinfo
"
).val(json.Table1[
0
].info);
}
}
);
Tag标签:
把dataset数据转换成json的格式
,
美丽达人
查看全文
相关阅读:
jquery 实现点击图片居住放大缩小
pycharm git工具与coding.net结合
Python 小知识点(10)--异常结构记录
Python 小知识点(9)--反射
Python 小知识点(8)-- __new__
@noi.ac
@noi.ac
@noi.ac
@noi.ac
@游记@ CQOI2019(十二省联考)
原文地址:https://www.cnblogs.com/aaa6818162/p/1573737.html
最新文章
play 学习 二: 关于play跨域
linux命令 把Windows 文件拷贝到linux
git学习 删除远程分支
git 学习 多个提交用同一个commit
MySQL 学习五 SQL实用函数
MySQL 学习四 SQL优化
第 十八 课 接口
第 十七 课
第 十六 课 Map
第 十五 课 Go 语言范围(Range)
热门文章
【前端技术】web 开发常见问题--GET POST 区别
【SQL】如何使用SQL like 方法和SQL [charlist] 通配符(SQL like的拓展)
【SQL】from a,b。表a 和b之间是什么关系?
【SQL】where 后不可以接聚合函数,都哪些是聚合函数?
【SQL】group by 和order by 的区别。
【数据库】SQL语句解析
【托业】【新托业TOEIC新题型真题】学习笔记11-题库六-P7
【托业】【新托业TOEIC新题型真题】学习笔记10-题库七-P7
【English】主语从句的引导词是如何选择?
【托业】托业(TOEIC)成绩 & 等级划分以及评分标准
Copyright © 2011-2022 走看看