json处理-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

json处理

水晶心泉 2017-05-11 14:06:36 3329
代码来自 龙臣旗舰店 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




JSON 数据格式
分享到
取消 提交回答
全部回答(0)
大数据
使用钉钉扫一扫加入圈子
+ 订阅

大数据计算实践乐园,近距离学习前沿技术

推荐文章
相似问题
推荐课程