代码来自 龙臣旗舰店 2017-5-11 13:34:38 本人仅代为整理
Func main()
$json = '{"data":{"word":"小叶紫檀","inList":[{"bidwordstr":"小叶紫檀a","date":"2015-01-01","impression":"312777","impressionRate":null,"click":"2480","price":"410038","ctr":"71","competition":"1667","cvr":"96","avgPrice":"140"},{"bidwordstr":"小叶紫檀","date":"2015-01-01","impression":"312777","impressionRate":null,"click":"2480","price":"410038","ctr":"71","competition":"1667","cvr":"96","avgPrice":"140"}]}}'
;获取jsonobject里面的值
$word = getJsonString($json, "data.word")
J_MsgBox($word)
;获list数组的大小
$count = getJsonLength($json, "data.inList")
J_MsgBox($count)
;遍历该数组
For $i = 0 to $count - 1
$inBidWord = getJsonString($json, "data.inList[" & $i & "].bidwordstr")
J_MsgBox("第" & $i & "个bidword:" & $inBidWord)
Next
EndFunc ;==>test1
;
;$json串
;$key 要获取值的键,数组的后面要跟[index] 如list[0]
Func getJsonString($json, $key)
$objSC = ObjCreate('ScriptControl')
$objSC.Language = 'JavaScript'
$objSC.AddCode('var ParseJson = ' & $json & ';')
Return $objSC.eval('ParseJson.' & $key)
EndFunc ;==>getJsonString
;
;$json串
;$key 要获取大小的数组
Func getJsonLength($json, $key)
$objSC = ObjCreate('ScriptControl')
$objSC.Language = 'JavaScript'
$objSC.AddCode('var ParseJson = ' & $json & ';')
Return $objSC.eval('ParseJson.' & $key & '.length')
EndFunc ;==>getJsonLength
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。