以文本方式查看主题 - 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=142794) |
-- 作者:blackzhu -- 发布时间:2019/11/6 15:08:00 -- json 如何获取键值 Dim json As String = "[{\'name\':\'李云龙\',\'age\':\'36\'},{\'name\':\'黄晓明\',\'age\':\'28\'}]" For Each ep As JToken In JArray.Parse(json) ........ Next 如何获取name gae 而不是 值 李云龙
|
-- 作者:reachtone -- 发布时间:2019/11/6 15:16:00 -- |
-- 作者:blackzhu -- 发布时间:2019/11/6 15:17:00 -- 哦 我看看 |
-- 作者:blackzhu -- 发布时间:2019/11/6 16:29:00 -- mingxis: [{"规格":"30*20cm","单位":"张","产品ID":"1c3710391809490cb56db732848b84b7","产品类别一":"办公用品","产品类别二":"印刷品","产品名称":"广告海报","产品编码":"2019-10-290535","GUID":"ET8iNyTqNTrRxeGHzRkIfS5PkfHPPpEy","入库ID":"M1mZm8cxzTezv3yYVJxAPzkZiw9KgoOX","品牌":"3M","产品图片":"045.png","出库ID":"K6oOcXcBhZi6z9SZzSuE8EAgw6WTfFAx","目前库存":"10"},{"规格":"20ml","单位":"瓶","产品ID":"2a2a016760444ccf9efefb437575b675","产品类别一":"医疗耗材","产品类别二":"常规耗材","产品名称":"碘甘油","产品编码":"10WZ170727004","GUID":"S5b4A3JKdYBAIwQjj8ShxFC30oIcXkpB","入库ID":"M1mZm8cxzTezv3yYVJxAPzkZiw9KgoOX","品牌":"","产品图片":"004.png","出库ID":"K6oOcXcBhZi6z9SZzSuE8EAgw6WTfFAx","目前库存":"20"}] 这个动态生成的json,我想拼接成插如数据库的语句 For Each ep As JToken In JArray.Parse(mingxis)
cmd.CommandText = "Insert Into 产品出库明细 (规格,单位,产品ID,产品类别一,产品类别二,产品名称,产品编码,GUID,出库ID,品牌,出库数量,产品图片,入库ID,目前库存,说明) Values(\'" & ep("规格").ToString() & "\',\'" & ep("单位").ToString() & "\',\'" & ep("产品ID").ToString() & "\',\'" & ep("产品类别一").ToString() & "\',\'" & ep("产品类别二").ToString() & "\',\'" & ep("产品名称").ToString() & "\',\'" & ep("产品编码").ToString() & "\',\'" & ep("GUID").ToString() & "\',\'" & ep("出库ID").ToString() & "\',\'" & ep("品牌").ToString() & "\',\'" & ep("出库数量").ToString() & "\',\'" & ep("产品图片").ToString() & "\',\'" & ep("入库ID").ToString() & "\',\'" & ep("目前库存").ToString() & "\',\'" & ep("说明").ToString() & "\')"
index += cmd.ExecuteNonQuery()
Next 但是这个语句发现动态进来的json进来的键值对,会变,所以生成错误 [此贴子已经被作者于2019/11/6 16:29:35编辑过]
|
-- 作者:有点蓝 -- 发布时间:2019/11/6 16:32:00 -- 想怎么处理? |
-- 作者:blackzhu -- 发布时间:2019/11/6 16:38:00 -- 按照{} 一对 根据键值对生成一条 插入数据的语句 [此贴子已经被作者于2019/11/6 16:38:24编辑过]
|
-- 作者:有点蓝 -- 发布时间:2019/11/6 16:51:00 -- For Each ep As JToken In JArray.Parse(mingxis) dim sql as string = "Insert Into 产品出库明细 (" dim sqlvalue as string = "Values(" for each jp as object in ep sql = sql & jp.name & "," sqlvalue = sqlvalue & "\'" & jp.value & "\'," next dim sql2 as string = sql.trim(",") & ") " & sqlvalue.trim(",") & ")" msgbox(sql2)
|
-- 作者:blackzhu -- 发布时间:2019/11/6 16:57:00 -- 我靠 我犯了一个低级错误,我把插入语句 嵌套进去了.笨死了 |