以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 当前行如何生成json? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=147034) |
-- 作者:sloyy -- 发布时间:2020/3/8 12:54:00 -- 当前行如何生成json? 我看帮助里面都是json拼接而成,后来查到一句: 根据现有对象生成JSON。 我想把某表的当前行生成json,除了拼接,可以用上面的语句生成吗?该怎么做? |
-- 作者:chen37280600 -- 发布时间:2020/3/8 14:15:00 -- 送你2个内部函数 Row2JObject: Dim dr As DataRow = args(0) Dim jo As JObject = args(1) For Each dc As DataCol In dr.DataTable.DataCols If dc.IsString Then jo(dc.Name) = CStr(dr(dc.Name)) Else If dc.IsBoolean Then jo(dc.Name) = CBool(dr(dc.Name)) Else If dc.IsNumeric Then jo(dc.Name) = Val(dr(dc.Name)) Else If dc.IsDate Then If dr.Isnull(dc.Name) =False Then jo(dc.Name) = CStr(dr(dc.Name)) Else jo(dc.Name) = "" End If End If Next Table2Json: Dim e As RequestEventArgs = args(0) Dim dt As DataTable = args(1) Dim jo As New JObject Dim ja As New JArray jo("list") =ja For i As Integer =0 To (dt.DataRows.Count - 1) Dim jo2 As new JObject ja.Add(jo2) Dim dr As DataRow = dt.DataRows(i) Functions.Execute("Row2JObject",dr,jo2) Next e.WriteString(CompressJson(jo)) \'jo就是你要的最终json [此贴子已经被作者于2020/3/8 14:16:21编辑过]
|
-- 作者:sloyy -- 发布时间:2020/3/8 14:59:00 -- 太感谢了 |
-- 作者:ljz -- 发布时间:2020/11/26 0:37:00 -- |