问题描述
- 求ASP解析JSON打印所有的目录和节点和值
-
水平太差,使用ASP自带的解析涵数后不知道如何输出里面的节点和内容信息function ToObject(json) { var o; eval("o=" + json); return o; } set obj1 = ToObject(teststr) Response.Write obj1.title & "<br />"本人到这就卡住了
上面代码是用来解析的,但是我只能打印出第一个title=“最攒劲乡镇街道”的值,后面的就不知道怎么操作了,求高手指教,附带JSON数据
{"title":"最攒劲乡镇街道","vote_permission":2,"expire_time":1430406000,"total_person":12889,"vote_subject":[{"type":1,"title":"戳出你心中最攒劲的乡镇!","options":[{"name":"物流重镇三工","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIyKZ5GCL8sZFg8yVQDK4ZkCQ6BDBF2Zh9M3VADI5MYRXkFqTjOFS8Uw/0?wx_fmt=jpeg","cnt":855,"selected":false},{"name":"区镇合一榆树沟","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIM6O7nuD77BRwcYxCnZlFvpClNnVNib9C7UUe1P29SAichGSknHb565BA/0?wx_fmt=jpeg","cnt":2010,"selected":false},{"name":"宜居创业之镇大西渠","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIACoqqFrafyGA6G8lbvJ1UfqLB8dylmLk9mZxfqpKw3LuDm4NLx0guw/0?wx_fmt=jpeg","cnt":2309,"selected":false},{"name":"矿业重镇硫磺沟","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIxeV6Z0zXyncCEWlzPQHIkrhurC4AajjHd4H2liaYVtDwoia5Wc0YLBgQ/0?wx_fmt=jpeg","cnt":1397,"selected":false},{"name":"渔米之乡六工","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIvHdrZ9r8sq6c2XHUtvovD4F4w6EmGuObNY4Mo97uHDWg5cde6icZMiag/0?wx_fmt=jpeg","cnt":743,"selected":false},{"name":"“花儿之乡”二六工镇","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIYBq22k40P8YJNkFIgOWJE2HOse1ee184F0icnjkEHJpEhL9LNTsuJTA/0?wx_fmt=jpeg","cnt":715,"selected":false},{"name":"生态宜居滨湖镇","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIISxHWjb8kNsic6SS5TOicrmDJBSf3gUtyFElxM42ynFW1JL3LcT0K8ctg/0?wx_fmt=jpeg","cnt":2175,"selected":false},{"name":"特色风情阿什里","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIQ2K0UII39wjSJAA1KJjziccHkjakOUyFJQKRlAYm7tnoQXYVFrq0ibEg/0?wx_fmt=jpeg","cnt":782,"selected":false},{"name":"定居样板庙尔沟","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYII3zG9RETg4pfD3sqGsFRGliczib0swxwjibDU9micd5lXPQnM4YPU3Fd2cQ/0?wx_fmt=jpeg","cnt":793,"selected":false},{"name":"生态农业旅游强镇佃坝","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIZMwJ4TBIYNKPZicTQKGp4EthF44g0lTVpv7GeapavgnrI8qpQPl8ZYw/0?wx_fmt=jpeg","cnt":1110,"selected":false}],"total_cnt":12889,"vote_id":617881},{"type":1,"title":"戳出你心中最攒劲街道!","options":[{"name":"延安北路街道","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIRxYQReiaFJuVNBzicbXG5Ty6gvzI4gVN9T3O5GnB71ynpZic1GNMr4tww/0?wx_fmt=jpeg","cnt":2627,"selected":false},{"name":"北京南路街道","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIC2QUpZvQFh8v3nxkDwxbQstKZsGDS3LEqqWAecdvHpHQDWm6Ie1Haw/0?wx_fmt=jpeg","cnt":2185,"selected":false},{"name":"宁边路街道","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIEOYNDk7Sp4V8xgiaou5CdeBURyXAHS0dIzcff6Fd9Mr9J1I65l5jOgg/0?wx_fmt=jpeg","cnt":1772,"selected":false},{"name":"绿洲路街道","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIcnKSaYhacAdmd72Sia3y6dB15SDCzvAYfEy1vFt8H38Jc2a9xzBPZBg/0?wx_fmt=jpeg","cnt":1819,"selected":false},{"name":"中山路街道","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIbGibWJic5Du2cy5icGa8mUcuOD2lTSBAXOmtZr9ic3oUqn6zCsS5kPduEQ/0?wx_fmt=jpeg","cnt":2264,"selected":false},{"name":"建国路街道","url":"http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIjEYfw0p0vGqBWEuq49pQcyeB8bv2IxlOBPvoicJ5mlsOKvs1MHg8x1g/0?wx_fmt=jpeg","cnt":2221,"selected":false}],"total_cnt":12888,"vote_id":617882}],"super_vote_id":412550,"del_flag":0}
解决方案
解析全部用jscript,不用用vbscript,你用jscript eval出来的json对象包含json数组vbscript不知道怎么解析。。。
要么你就下载这个类,用下面的代码进行解析:asp json类库
<!--#include file="aspJSON1.17.asp"-->
<%
teststr = "{""title"":""最攒劲乡镇街道"",""vote_permission"":2,""expire_time"":1430406000,""total_person"":12889,""vote_subject"":[{""type"":1,""title"":""戳出你心中最攒劲的乡镇!"",""options"":[{""name"":""物流重镇三工"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIyKZ5GCL8sZFg8yVQDK4ZkCQ6BDBF2Zh9M3VADI5MYRXkFqTjOFS8Uw/0?wx_fmt=jpeg"",""cnt"":855,""selected"":false},{""name"":""区镇合一榆树沟"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIM6O7nuD77BRwcYxCnZlFvpClNnVNib9C7UUe1P29SAichGSknHb565BA/0?wx_fmt=jpeg"",""cnt"":2010,""selected"":false},{""name"":""宜居创业之镇大西渠"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIACoqqFrafyGA6G8lbvJ1UfqLB8dylmLk9mZxfqpKw3LuDm4NLx0guw/0?wx_fmt=jpeg"",""cnt"":2309,""selected"":false},{""name"":""矿业重镇硫磺沟"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIxeV6Z0zXyncCEWlzPQHIkrhurC4AajjHd4H2liaYVtDwoia5Wc0YLBgQ/0?wx_fmt=jpeg"",""cnt"":1397,""selected"":false},{""name"":""渔米之乡六工"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIvHdrZ9r8sq6c2XHUtvovD4F4w6EmGuObNY4Mo97uHDWg5cde6icZMiag/0?wx_fmt=jpeg"",""cnt"":743,""selected"":false},{""name"":""“花儿之乡”二六工镇"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIYBq22k40P8YJNkFIgOWJE2HOse1ee184F0icnjkEHJpEhL9LNTsuJTA/0?wx_fmt=jpeg"",""cnt"":715,""selected"":false},{""name"":""生态宜居滨湖镇"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIISxHWjb8kNsic6SS5TOicrmDJBSf3gUtyFElxM42ynFW1JL3LcT0K8ctg/0?wx_fmt=jpeg"",""cnt"":2175,""selected"":false},{""name"":""特色风情阿什里"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIQ2K0UII39wjSJAA1KJjziccHkjakOUyFJQKRlAYm7tnoQXYVFrq0ibEg/0?wx_fmt=jpeg"",""cnt"":782,""selected"":false},{""name"":""定居样板庙尔沟"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYII3zG9RETg4pfD3sqGsFRGliczib0swxwjibDU9micd5lXPQnM4YPU3Fd2cQ/0?wx_fmt=jpeg"",""cnt"":793,""selected"":false},{""name"":""生态农业旅游强镇佃坝"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIZMwJ4TBIYNKPZicTQKGp4EthF44g0lTVpv7GeapavgnrI8qpQPl8ZYw/0?wx_fmt=jpeg"",""cnt"":1110,""selected"":false}],""total_cnt"":12889,""vote_id"":617881},{""type"":1,""title"":""戳出你心中最攒劲街道!"",""options"":[{""name"":""延安北路街道"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIRxYQReiaFJuVNBzicbXG5Ty6gvzI4gVN9T3O5GnB71ynpZic1GNMr4tww/0?wx_fmt=jpeg"",""cnt"":2627,""selected"":false},{""name"":""北京南路街道"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIC2QUpZvQFh8v3nxkDwxbQstKZsGDS3LEqqWAecdvHpHQDWm6Ie1Haw/0?wx_fmt=jpeg"",""cnt"":2185,""selected"":false},{""name"":""宁边路街道"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIEOYNDk7Sp4V8xgiaou5CdeBURyXAHS0dIzcff6Fd9Mr9J1I65l5jOgg/0?wx_fmt=jpeg"",""cnt"":1772,""selected"":false},{""name"":""绿洲路街道"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIcnKSaYhacAdmd72Sia3y6dB15SDCzvAYfEy1vFt8H38Jc2a9xzBPZBg/0?wx_fmt=jpeg"",""cnt"":1819,""selected"":false},{""name"":""中山路街道"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIbGibWJic5Du2cy5icGa8mUcuOD2lTSBAXOmtZr9ic3oUqn6zCsS5kPduEQ/0?wx_fmt=jpeg"",""cnt"":2264,""selected"":false},{""name"":""建国路街道"",""url"":""http://mmbiz.qpic.cn/mmbiz/Y2eca8dznyzbU5cV9f5F5QPYficVYicYIIjEYfw0p0vGqBWEuq49pQcyeB8bv2IxlOBPvoicJ5mlsOKvs1MHg8x1g/0?wx_fmt=jpeg"",""cnt"":2221,""selected"":false}],""total_cnt"":12888,""vote_id"":617882}],""super_vote_id"":412550,""del_flag"":0}"
set o=new aspJSON
o.loadjson(teststr)
response.Write o.data("title")&"<br/>"
''''此节点其他属性
for each vote_subject in o.data("vote_subject")
set item=o.data("vote_subject")(vote_subject)
response.Write item.item("type")&"<br>"
response.Write item.item("title")&"<br>"
'此节点下其他属性
for each options in item.item("options")
set itemop=item.item("options")(options)
response.Write itemop.item("name")&"<br>"
response.Write itemop.item("url")&"<br>"
'此节点下其他属性
next
next
set o=nothing
%>