table to json
来源:互联网 发布:网络倩女幽魂2挂机地点 编辑:程序博客网 时间:2024/05/29 14:27
json 格式:
{ "T_blog":
[
{"id":"14","title":"北京奥运开幕式","addtime":"2008-08-08"},
{"id":"15","title":"网络文化","addtime":"2008-09-12"},
{"id":"17","title":"北京下雨了","addtime":"2008-09-19"},
{"id":"21","title":"深圳地铁通了","addtime":"2008-09-25"}
]
}
1 思路: 遍历表格,将表中的数据按照 json格式 拼接;
public static string CreateJsonParameters(DataTable dt)
{
/**//**/
/**//* /****************************************************************************
* Without goingin to the depth of the functioning of this Method, i will try to give an overview
* As soon as this method gets a DataTable it starts to convert it into JSON String,
* it takes each row and in each row it grabs the cell name and its data.
* This kind of JSON is very usefull when developer have to have Column name of the .
* Values Can be Access on clien in this way. OBJ.HEAD[0].<ColumnName>
* NOTE: One negative point. by this method user will not be able to call any cell by its index.
* *************************************************************************/
StringBuilder JsonString = new StringBuilder();
//Exception Handling
if (dt != null && dt.Rows.Count > 0)
{
JsonString.Append("{ ");
JsonString.Append("\"T_blog\":[ ");
for (int i = 0; i < dt.Rows.Count; i++)
{
JsonString.Append("{ ");
for (int j = 0; j < dt.Columns.Count; j++)
{
if (j < dt.Columns.Count - 1)
{
JsonString.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\",");
}
else if (j == dt.Columns.Count - 1)
{
JsonString.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\"");
}
}
/**//**/
/**//*end Of String*/
if (i == dt.Rows.Count - 1)
{
JsonString.Append("} ");
}
else
{
JsonString.Append("}, ");
}
}
JsonString.Append("]}");
return JsonString.ToString();
}
else
{
return null;
}
}
2 这是一种各位先进的方式: json 类,对象的方法 将一个model对象序列化为json对象
using System.Web.Script.Serialization;
protected void LoadEts()
{
JavaScriptSerializer json = new JavaScriptSerializer();
DataTable ds_event = bll_event.GetAllList().Tables[0];
if (ds_event.Rows.Count > 0)
{
string str = string.Empty;
for (int i = 0; i < ds_event.Rows.Count; i++)
{
DataRow dr=ds_event.Rows[i];
Model.events oneevent = new Maticsoft.Model.events();
oneevent.id =int.Parse(dr["id"].ToString());
oneevent.title = dr["title"].ToString();
oneevent.username=dr["username"].ToString();
oneevent.pic=dr["pic"].ToString();
oneevent.address = dr["address"].ToString();
oneevent.cityaddress = dr["cityaddress"].ToString();
oneevent.starttime =DateTime.Parse(dr["starttime"].ToString());
oneevent.endtime =DateTime.Parse(dr["endtime"].ToString());
oneevent.contents = dr["contents"].ToString();
oneevent.classname = dr["classname"].ToString();
oneevent.seecount =int.Parse(dr["seecount"].ToString());
oneevent.joincount =int.Parse(dr["joincount"].ToString());
oneevent.jionmoney = dr["jionmoney"].ToString();
oneevent.personcount =int.Parse(dr["personcount"].ToString());
oneevent.tudu = dr["tudu"].ToString();
oneevent.viewcount =int.Parse(dr["viewcount"].ToString());
str += json.Serialize(oneevent);//对象 序列化的方法
}
this.Literal1.Text = str.ToString();
}
}
- table to json
- Lua Table to Json
- R table to latex table
- json转table
- table数据转为json
- json 输出到 table
- lua table to string,string to table
- table to csv
- Internal table to PDF
- Insert row to table
- lua table to string
- Jquery根据JSON生成Table
- Json生成Lua Table工具
- bootstrap-table解析嵌套json
- Oracle backup one table to another table.
- PostgreSQL change unlogged table to logged table
- Linq to JSON/Json.NET
- js string to json / json to string
- Linux线程信号
- mysql中整型的储存范围
- 推荐mvc3.0 学习网址(只有一个)
- 100分求一个PHP正则公式
- [开源框架推荐]VTD-XML:世界上最快的XML处理框架 .
- table to json
- ER图
- UML之用例图
- url 中文乱码问题
- 非常有用:简单的RPC java实现
- 实现iOS应用图标右上角数字badge number提醒
- 趣味谈UML类图
- SSRF pentest
- vs10 发布项目