jsoncpp库如何控制插入项在json字符串中的
2个回答
展开全部
引入using Newtonsoft.Json;
数据查询后填充到DataTable ,再转 JsonConvert.SerializeObject
简单例子:
DataTable dt = new DataTable();
DataColumn dcName = new DataColumn("Name");
DataColumn dcAge = new DataColumn("Age");
DataColumn dcCity = new DataColumn("City");
dt.Columns.Add(dcName);
dt.Columns.Add(dcAge);
dt.Columns.Add(dcCity);
for (int i = 0; i < 10; i++)
{
DataRow dr = dt.NewRow();
dr[0] = "Name" + i;
dr[1] = "Age" + i;
dr[2] = "City" + i;
dt.Rows.Add(dr);
}
json = JsonConvert.SerializeObject(dt);
数据查询后填充到DataTable ,再转 JsonConvert.SerializeObject
简单例子:
DataTable dt = new DataTable();
DataColumn dcName = new DataColumn("Name");
DataColumn dcAge = new DataColumn("Age");
DataColumn dcCity = new DataColumn("City");
dt.Columns.Add(dcName);
dt.Columns.Add(dcAge);
dt.Columns.Add(dcCity);
for (int i = 0; i < 10; i++)
{
DataRow dr = dt.NewRow();
dr[0] = "Name" + i;
dr[1] = "Age" + i;
dr[2] = "City" + i;
dt.Rows.Add(dr);
}
json = JsonConvert.SerializeObject(dt);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询