Foxtable(狐表)用户栏目专家坐堂 → 当前行如何生成json?


  共有3044人关注过本帖树形打印复制链接

主题:当前行如何生成json?

帅哥哟,离线,有人找我吗?
chen37280600
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1279 积分:7953 威望:0 精华:4 注册:2017/12/31 14:53:00
  发帖心情 Post By: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编辑过]

 回到顶部