在C#中将DataTable转换为JSON我想从数据库中获取记录到DataTable.然后将DataTable进入JSON对象。将JSON对象返回给我的JavaScript函数。我用这,这个通过调用:string result = JsonConvert.SerializeObject(DatatableToDictionary(queryResult, "Title"), Newtonsoft.Json.Formatting.Indented);若要将DataTable转换为JSON,它将正确工作并返回以下内容:{
"1": {
"viewCount": 703,
"clickCount": 98
},
"2": {
"viewCount": 509,
"clickCount": 85
},
"3": {
"viewCount": 578,
"clickCount": 86
},
"4": {
"viewCount": 737,
"clickCount": 108
},
"5": {
"viewCount": 769,
"clickCount": 130
}}但我希望它返回如下:{"records":[{"Title": 1,"viewCount": 703,"clickCount": 98},{"Title": 2,"viewCount": 509,"clickCount": 85},{"Title": 3,"viewCount": 578,"clickCount": 86},{"Title": 4,"viewCount": 737,"clickCount": 108},{"Title": 5,"viewCount": 769,"clickCount": 130}]} 我该怎么做?3 回答
3 回答
- 3 回答
- 0 关注
- 408 浏览
添加回答
举报
0/150
提交
取消