以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- Jobject 遍历问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=174411) |
-- 作者:qq252476275 -- 发布时间:2022/1/14 8:34:00 -- Jobject 遍历问题 Dim jo As JObject = args(1) \' 转为Object Dim jc As JObject = JObject.Parse(jo("content").ToString()) Dim strSQL As String = "" \' 先查询表格,以便处理日期列 strSQL = "Select Top 1 " For Each jp As JProperty In jc strSQL = strSQL & "[" & jp.Name.ToString() & "] , " Next 报错 JToken 不能转为 JProperty 改用 as JToken 报 JToken不能转为JToken ------ Dim arrData As New JArray Dim jObj As New JObject jObj("tableName") = "bm_user" Dim objContent As new JObject objContent("id") = 1 objContent("name") = "fzr" jObj("content") = objContent jObj("where") = "keyong = 1" arrData.Add(jObj) Dim jObj1 As New JObject jObj1("tableName") = "bm_units" Dim objContent1 As new JObject objContent1("id") = 2 objContent1("name") = "yy" jObj1("content") = objContent1 jObj1("where") = "keyong = 2" arrData.Add(jObj1) \'Dim js As String = arrData.ToString() \'output.show(js) For Each jt As JToken In arrData output.show(jt.ToString()) If jt("user") Is Nothing Then \' MessageBox.Show("user键值不存在!") End If For Each jp As JProperty In jt output.show(jp.ToString()) \' output.show(jp("where").ToString()) \' output.show(jp("tableName").ToString()) output.show(" ") Next Next 这样使用 as jProperty 却是正常的 |
-- 作者:有点蓝 -- 发布时间:2022/1/14 9:02:00 -- jo("content")是什么内容?发上来测试一下 |
-- 作者:qq252476275 -- 发布时间:2022/1/14 9:10:00 -- 没有调用这个函数呢, 只是写了个内部函数 准备写成 下面代码中的content Dim arrData As New JArray Dim jObj As New JObject jObj("tableName") = "bm_user" Dim objContent As new JObject objContent("id") = 1 objContent("name") = "fzr" jObj("content") = objContent jObj("where") = "keyong = 1" arrData.Add(jObj) Dim jObj1 As New JObject jObj1("tableName") = "bm_units" Dim objContent1 As new JObject objContent1("id") = 2 objContent1("name") = "yy" jObj1("content") = objContent1 jObj1("where") = "keyong = 2" arrData.Add(jObj1) \'Dim js As String = arrData.ToString() \'output.show(js) For Each jt As JToken In arrData output.show(jt.ToString()) If jt("user") Is Nothing Then \' MessageBox.Show("user键值不存在!") End If For Each jp As JProperty In jt output.show(jp.ToString()) \' output.show(jp("where").ToString()) \' output.show(jp("tableName").ToString()) output.show(" ") Next Next [此贴子已经被作者于2022/1/14 9:10:51编辑过]
|
-- 作者:有点蓝 -- 发布时间:2022/1/14 9:21:00 -- 那是一个键值对,要这样用: For Each jp As object In jc strSQL = strSQL & "[" & jp.key.ToString() & "] , " Next |
-- 作者:qq252476275 -- 发布时间:2022/1/14 9:53:00 -- 这个有相应的帮助文档吗? JObject , JArray , JToken , JProperty 都晕了 |
-- 作者:有点蓝 -- 发布时间:2022/1/14 10:00:00 -- https://www.newtonsoft.com/json |
-- 作者:qq252476275 -- 发布时间:2022/1/14 15:48:00 -- 如何 判断 content 是否存在呢? [此贴子已经被作者于2022/1/14 15:50:27编辑过]
|
-- 作者:有点蓝 -- 发布时间:2022/1/14 15:52:00 -- if jo("content") isnot nothing |
-- 作者:qq252476275 -- 发布时间:2022/1/14 16:41:00 -- JArray 元素 用 JToken Jobject 元素 用 JProperty 对吗? 还是 JProperty 用在哪里?
|
-- 作者:有点蓝 -- 发布时间:2022/1/14 16:54:00 -- 看官方文档说明把 |