以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  钉钉接口  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=173545)

--  作者:BG小白
--  发布时间:2021/12/4 21:24:00
--  钉钉接口
For Each dr As DataRow In DataTables("表B").DataRows
    Dim ul As String = "https://oapi.dingtalk.com/topapi/user/listsimple?access_token={0}"
    Dim hc As New HttpClient(CExp(ul,Functions.Execute("access_token")))
    Dim jo As New JObject
    jo("dept_id") = CStr(dr("第一列"))
    jo("cursor") = "0"
    jo("size") = "10"
    hc.Content = jo.ToString()
    jo = JObject.Parse(hc.GetData())
    Dim dt As DataTable = DataTables("表C")
    Dim w As DataRow
    If jo("errcode") = "0" Then
        For Each jt As JToken In jo("result")("list")
            w = dt.Find("userid = \'"& jt("userid").tostring &"\'")
            If w IsNot Nothing Then
                w("name") = jt("name").tostring
            Else
                w = dt.AddNew
                w("userid") = jt("userid").tostring
                w("name") = jt("name").tostring
            End If
            w.Save
        Next
    Else
        MessageBox.Show(jo.ToString)
    End If
Next

为什么把这段代码放到函数里面,就会显示详细错误信息:
调用的目标发生了异常。
索引超出了数组界限。

--  作者:BG小白
--  发布时间:2021/12/5 0:21:00
--  

此主题相关图片如下:qq图片20211205001804.png
按此在新窗口浏览图片
还有这个还怎么将返回的值写到表里面去啊
通过下面这种不行
Dim dt As DataTable = DataTables("表C")
    Dim w As DataRow
    If jo("errcode") = "0" Then
        For Each jt As JToken In jo("result")("list")
            w = dt.Find("userid = \'"& jt("userid").tostring &"\'")
            If w IsNot Nothing Then
                w("name") = jt("name").tostring
            Else
                w = dt.AddNew
                w("userid") = jt("userid").tostring
                w("name") = jt("name").tostring
            End If

--  作者:有点蓝
--  发布时间:2021/12/5 20:39:00
--  
看2楼结果,result是一个数组,不是对象,应该是:jo("result")(0)("field_list")


--  作者:BG小白
--  发布时间:2021/12/5 23:04:00
--  
谢谢
[此贴子已经被作者于2021/12/5 23:19:55编辑过]

--  作者:有点蓝
--  发布时间:2021/12/5 23:14:00
--  
if  jo("label") isnot nothing then