以文本方式查看主题
- 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=124403)
|
-- 作者:zoyong
-- 发布时间:2018/9/5 16:20:00
-- json取值
Dim st As New Date(1970,1,1,8,0,0) Dim t1 As Integer = CInt((Date.Today.AddDays(-100) - st).TotalSeconds()) \'时间戳开始时间 Dim t2 As Integer = CInt((Date.Now - st).TotalSeconds()) \'时间戳结束时间
Dim ur As String = "https://qyapi.weixin.qq.com/cgi-bin/corp/getapprovaldata?access_token={0}" Dim hc As new HttpClient(Cexp(ur,Functions.Execute("GetQYAccessToken2"))) \'企业号应用 Dim jo As New JObject jo("starttime") = t1 jo("endtime") = t2 hc.Content = jo.Tostring() jo = JObject.Parse(hc.GetData) Dim json As String = jo("data").ToString() Dim ja As JArray = Jarray.Parse(json)
For i As Integer = 0 To ja.Count - 1 If ja(i)("spname").ToString() = " 香烟领用" Then Dim spbh As String = ja(i)("sp_num").ToString() \'判断是否存在相同的审批编号行 Dim dr As DataRow = DataTables("微信审批表香烟").Find("审批编号 = \'" & spbh & "\'") If dr Is Nothing Then \'如果不存在想同审批编号 Dim r As Row =Tables("微信审批表香烟").AddNew() r("单据类型") = ja(i)("spname").ToString() \'审批名称(请假,香烟,自定义审批名称) r("审批编号") = ja(i)("sp_num").ToString() \'审批单号 r("申请部门") = ja(i)("apply_org").ToString() \'申请人部门 r("申请人") = ja(i)("apply_name").ToString() \'申请人姓名 r("审批状态") = ja(i)("sp_status").ToString() \'审批状态:1审批中;2 已通过;3已驳回;4已取消;6通过后撤销;10已支付 r("审批人") = ja(i)("approval_name").ToString().Replace("""","").Replace("[","").Replace("]","").Replace(vblf,"") \'审批人姓名 r("提交时间") = ja(i)("apply_time").ToString() \'审批单提交时间 \' r("附件") = ja(i)("mediaids").ToString() \'审批的附件media_id,可使用media/get获取附件 r("comm") = ja(i)("comm")("apply_data").ToString() \'获取详细信息 r("userid") = ja(i)("apply_user_id").ToString() \'审批单提交者的userid r("附件") = """[" & r("comm").Replace("""","\'") & "]""" \'替换双引号为单引号,并加入"[]" r("次数") = "1"
Dim json1 As String = r("附件") For Each ep As JToken In JArray.Parse(json1) r("用途") = ep("item-1494250993171")("value").ToString() r("香烟类别") = ep("item-1529756528001")("value").ToString().Replace("[","").Replace("]","") r("数量") = ep("item-1494251019660")("value").ToString() Next
Dim csr As String csr = ja(i)("notify_name").ToString().Replace(vblf,"") If len(csr) = 2 Then r("抄送人") = "" Else Dim s As String s = "" For Each v As JToken In JArray.Parse(csr) s = s & "," & v.ToString Next r("抄送人") = s.TrimStart(",") End If
End If End If Next
错误提示:
.NET Framework 版本:2.0.50727.8793 Foxtable 版本:2018.8.30.1 错误所在事件:窗口,QQ信息,香烟领用,Click 详细错误信息: Error reading JArray from JsonReader. Current JsonReader item is not an array: String. Path \'\', line 1, position 562.
加上红色的代码,就会出现上面的错误,请大神帮忙修改
|
-- 作者:zoyong
-- 发布时间:2018/9/5 16:25:00
--
Dim json As String = "[{\'item-1494250993171\':{\'id\':\'item-1494250993171\',\'title\':\'用 途\',\'type\':\'textarea\',\'validate\':true,\'value\':\'朱溪堤防\',\'warning\':\'\'},\'item-1529756528001\':{\'id\':\'item- 1529756528001\',\'locked\':false,\'placeholder\':\'\',\'title\':\'香烟类 别\',\'type\':\'checkbox\',\'un_print\':false,\'validate\':true,\'value\':[\'中华(软)\'],\'warning\':\'\',\'configvalue\':\'中华 (硬),中华(软),利群,其他\'},\'item-1494251019660\':{\'id\':\'item-1494251019660\',\'title\':\'数量 (包)\',\'type\':\'number\',\'validate\':true,\'value\':\'50\',\'warning\':\'\'},\'item-1494251026821\':{\'id\':\'item- 1494251026821\',\'title\':\'附件\',\'type\':\'file\',\'validate\':false,\'value\':\'\',\'warning\':\'\'}}]" For Each ep As JToken In JArray.Parse(json) Output.Show(ep("item-1494250993171")("value").ToString() ) Output.Show(ep("item-1529756528001")("value").ToString().Replace("[","").Replace("]","") ) Output.Show(ep("item-1529756528001")("value").ToString() ) Next
在命令窗口中执行又是正常的
|
-- 作者:zoyong
-- 发布时间:2018/9/5 16:27:00
--
Dim json1 As String = r("附件")
错在这行代码了,不知道怎么改,大脑死机了
|
-- 作者:有点甜
-- 发布时间:2018/9/5 16:38:00
--
msgbox(r("附件")) 弹出什么?如果值为空白,或者不正确,肯定报错。
|
-- 作者:zoyong
-- 发布时间:2018/9/5 16:40:00
--
此主题相关图片如下:qq截图20180905164231.jpg
内容正常附值了
"[{\'item-1494250993171\':{\'id\':\'item-1494250993171\',\'title\':\'用途\',\'type\':\'textarea\',\'validate\':true,\'value\':\'里加山水库检查会议\',\'warning\':\'\'},\'item-1529756528001\':{\'id\':\'item-1529756528001\',\'locked\':false,\'placeholder\':\'\',\'title\':\'香烟类别\',\'type\':\'checkbox\',\'un_print\':false,\'validate\':true,\'value\':[\'中华(硬)\'],\'warning\':\'\',\'configvalue\':\'中华(硬),中华(软),利群,其他\'},\'item-1494251019660\':{\'id\':\'item-1494251019660\',\'title\':\'数量(包)\',\'type\':\'number\',\'validate\':true,\'value\':\'20\',\'warning\':\'\'},\'item-1494251026821\':{\'id\':\'item-1494251026821\',\'title\':\'附件\',\'type\':\'file\',\'validate\':false,\'value\':\'\',\'warning\':\'\'}}]"
[此贴子已经被作者于2018/9/5 16:45:06编辑过]
|
-- 作者:zoyong
-- 发布时间:2018/9/5 17:00:00
--
.NET Framework 版本:2.0.50727.8793 Foxtable 版本:2018.8.30.1 错误所在事件:窗口,QQ信息,香烟领用,Click 详细错误信息: Error reading JArray from JsonReader. Current JsonReader item is not an array: String. Path \'\', line 1, position 590.
|
-- 作者:有点甜
-- 发布时间:2018/9/5 17:24:00
--
output.show(r("附件"))
然后看命令窗口显示什么内容,拷贝显示的内容测试。如果还是没问题,就不是你红色那段代码有问题。
|
-- 作者:zoyong
-- 发布时间:2018/9/6 14:17:00
--
以下代码在命令窗口运行正常 Dim json As String = "[{\'item-1494250993171\':{\'id\':\'item-1494250993171\',\'title\':\'用 途\',\'type\':\'textarea\',\'validate\':true,\'value\':\'朱溪堤防\',\'warning\':\'\'},\'item-1529756528001\':{\'id\':\'item- 1529756528001\',\'locked\':false,\'placeholder\':\'\',\'title\':\'香烟类 别\',\'type\':\'checkbox\',\'un_print\':false,\'validate\':true,\'value\':[\'中华(软)\'],\'warning\':\'\',\'configvalue\':\'中华 (硬),中华(软),利群,其他\'},\'item-1494251019660\':{\'id\':\'item-1494251019660\',\'title\':\'数量 (包)\',\'type\':\'number\',\'validate\':true,\'value\':\'50\',\'warning\':\'\'},\'item-1494251026821\':{\'id\':\'item- 1494251026821\',\'title\':\'附件\',\'type\':\'file\',\'validate\':false,\'value\':\'\',\'warning\':\'\'}}]" For Each ep As JToken In JArray.Parse(json) Output.Show(ep("item-1494250993171")("value").ToString() ) Output.Show(ep("item-1494251019660")("value").ToString() ) Next
在DataColChanged中运行不了 If e.DataCol.Name = "审批模板信息" Then If e.DataRow.IsNull("审批模板信息") = False Then Dim json As String = e.DataRow("审批模板信息") For Each ep As JToken In JArray.Parse(json) e.DataRow("报销事由") = ep("item-1494250993171")("value").ToString() e.DataRow("报销金额") = ep("item-1494251019660")("value").ToString() Next End If
End If |
|
-- 作者:有点甜
-- 发布时间:2018/9/6 14:24:00
--
我测试没问题,请上传具体实例测试。
[此贴子已经被作者于2018/9/6 14:23:54编辑过]
|
-- 作者:zoyong
-- 发布时间:2018/9/6 14:41:00
--
DataColChanged
帮忙看看
[此贴子已经被作者于2018/9/6 15:19:24编辑过]
|