标题:请教JSON,用的是foxjson.dll,字符数组取值报错!
只看楼主
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:205
专家分:31
注 册:2010-12-23
结帖率:56.36%
已结贴  问题点数: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: 4
等 级:贵宾
威 望:11
帖 子:90
专家分:278
注 册: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
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:7 
useridlist是数组,不是对象

2021-12-06 11:10
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:205
专家分:31
注 册:2010-12-23
得分:0 
回复 3楼 吹水佬
大佬,是数组,要怎么改一下呢?
2021-12-06 11:14
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:205
专家分:31
注 册:2010-12-23
得分:0 
回复 2楼 foxfans
谢谢你的回复,你的方法很不错!
2021-12-06 11:15
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册: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
帖 子:205
专家分:31
注 册: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
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册: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
帖 子:205
专家分:31
注 册:2010-12-23
得分:0 
回复 8楼 吹水佬
谢谢大佬,你这样对!
2021-12-06 14:25
kangss
Rank: 4
等 级:贵宾
威 望:10
帖 子:138
专家分:237
注 册:2014-6-12
得分:7 
谢谢!学习了
2021-12-07 18:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-507770-1-1.html




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

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