| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2242 人关注过本帖, 1 人收藏
标题:请教JSON,用的是foxjson.dll,字符数组取值报错!
只看楼主 加入收藏
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
结帖率:58.02%
收藏(1)
已结贴  问题点数:20 回复次数:12 
请教JSON,用的是foxjson.dll,字符数组取值报错!
请教大佬:
原报文:
{"errcode":0,"errmsg":"ok","chat_info":{"owner":"0250452735598104","showHistoryType":0,"chatid":"chateca5eb08b7f98f17f5f63b2f731b954a","validationType":0,"useridlist":["01062505372440241082","31192441281231555","0250452735598104"],"icon":"@lALPDf0i0cmB28TNAljNAlg","openConversationId":"cidtYlM6oBqlSljhqpEIX8KRQ==","searchable":0,"chatBannedType":0,"managementType":0,"mentionAllAuthority":0,"conversationTag":2,"name":"测试001","status":1}}
使用过程:
ltype=oJson.item("chat_info").item("name").value  &&可以正常取到值
ltype=oJson.item("chat_info").item("useridlist").value &&无法正常取到值,请教这里如何取?
搜索更多相关主题的帖子: dll 取值 字符 报错 item 
2021-12-06 10:39
foxfans
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:113
专家分:324
注 册:2021-10-23
收藏
得分:7 
TEXT TO cJsonstr noshow
{"errcode":0,"errmsg":"ok","chat_info":{"owner":"0250452735598104","showHistoryType":0,"chatid":"chateca5eb08b7f98f17f5f63b2f731b954a","validationType":0,"useridlist":["01062505372440241082","31192441281231555","0250452735598104"],"icon":"@lALPDf0i0cmB28TNAljNAlg","openConversationId":"cidtYlM6oBqlSljhqpEIX8KRQ==","searchable":0,"chatBannedType":0,"managementType":0,"mentionAllAuthority":0,"conversationTag":2,"name":"测试001","status":1}}
ENDTEXT
m.cJsonStr=[var json=]+cJsonstr+[;]
m.oJs=CREATEOBJECT("MSScriptControl.ScriptControl")
m.oJs.Language="jscript"
m.oJs.addCode(m.cJsonStr)   
m.oSon=m.oJs.CodeObject.json.chat_info.useridlist
FOR EACH m.SubItem IN m.oSon
?m.SubItem &&这大概就是你要的值了
ENDFOR
RELEASE m.oJs
2021-12-06 11:07
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10609
专家分:43210
注 册:2014-5-20
收藏
得分:7 
useridlist是数组,不是对象

2021-12-06 11:10
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 3楼 吹水佬
大佬,是数组,要怎么改一下呢?
2021-12-06 11:14
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 2楼 foxfans
谢谢你的回复,你的方法很不错!
2021-12-06 11:15
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10609
专家分:43210
注 册:2014-5-20
收藏
得分:0 
回复 4楼 laibinhua
程序代码:
TEXT TO cJson TEXTMERGE NOSHOW PRETEXT 15
{"errcode":0,"errmsg":"ok","chat_info":{"owner":"0250452735598104","showHistoryType":0,"chatid":"chateca5eb08b7f98f17f5f63b2f731b954a","validationType":0,"useridlist":["01062505372440241082","31192441281231555","0250452735598104"],"icon":"@lALPDf0i0cmB28TNAljNAlg","openConversationId":"cidtYlM6oBqlSljhqpEIX8KRQ==","searchable":0,"chatBannedType":0,"managementType":0,"mentionAllAuthority":0,"conversationTag":2,"name":"测试001","status":1}}
ENDTEXT
sc = CREATEOBJECT("ScriptControl")
sc.Language = "JavaScript"
sc.addCode("var json="+cJson)   
? sc.eval("json.chat_info.useridlist[0]")
? sc.eval("json.chat_info.useridlist[1]")
? sc.eval("json.chat_info.useridlist[2]")
2021-12-06 11:27
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 2楼 foxfans
老师:用这个方法,又碰到个问题:
原始报文:
{"errcode":0,"errmsg":"ok","result":{"has_more":false,"list":[{"active":true,"admin":true,"avatar":"","boss":false,"dept_id_list":[1],"dept_order":176342269632077512,"exclusive_account":false,"hide_mobile":false,"leader":false,"mobile":"1378223750","name":"张三","state_code":"86","unionid":"7Az7l9unGiPeiPeliSJiPMwSxwiEiE","userid":"31192441281231555"},{"active":true,"admin":true,"avatar":"","boss":false,"dept_id_list":[1],"dept_order":176287327676115512,"exclusive_account":false,"hide_mobile":false,"leader":false,"mobile":"13333332616","name":"李四","state_code":"86","unionid":"3yp6KVDiiLaEiE","userid":"0250452735598104"},{"active":true,"admin":false,"avatar":"","boss":false,"dept_id_list":[1],"dept_order":176279123423347512,"exclusive_account":false,"hide_mobile":false,"leader":false,"mobile":"13122255731","name":"王五","state_code":"86","unionid":"nxiPrUYqlECM28QouwDa26QiEiE","userid":"01062505372440241082"}]},"request_id":"5nmgrf45ars4"}
我用你的方法,这样取所有人的姓名报错:
m.oJs=CREATEOBJECT("MSScriptControl.ScriptControl")
m.oJs.Language="jscript"
m.oJs.addCode(m.cJsonStr)   
m.oSon=m.oJs.CodeObject.json.result.list.name
FOR EACH m.SubItem IN m.oSon
?m.SubItem &&这大概就是你要的值了
ENDFOR
RELEASE m.oJs
2021-12-06 14:11
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10609
专家分:43210
注 册:2014-5-20
收藏
得分:0 
试试
m.oSon=m.oJs.CodeObject.json.result.list
FOR EACH m.SubItem IN m.oSon
?m.SubItem.name  &&这大概就是你要的值了
ENDFO
2021-12-06 14:24
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 8楼 吹水佬
谢谢大佬,你这样对!
2021-12-06 14:25
kangss
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:14
帖 子:277
专家分:615
注 册:2014-6-12
收藏
得分:7 
谢谢!学习了
2021-12-07 18:33
快速回复:请教JSON,用的是foxjson.dll,字符数组取值报错!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018481 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved