Iterating though a JSON return using ASP Xtreme Ev

2019-09-13 02:24发布

I'm trying to parse a return from Twitter using classic ASP with ASP Xtreme Evolution JSON Parser https://github.com/nagaozen/asp-xtreme-evolution/blob/master/lib/axe/classes/Parsers/json2.asp

To keep things simple, here's a trimmed JSON return:

[{
    "user": {
    "id": 19720970
    }
}, {
    "user": {
    "id": 201195798
    }
}, {
    "user": {
    "id": 19768935
    }
}]

What I need to do is iterate through each user to discover the id. The best I've got so far only returns the last id:

dim Info : set Info = JSON.parse(join(array(jsonResponse)))
dim key : For Each key in Info.user.keys()
    Response.Write Info.user.id & "<br>" 'only 19768935 is printed
Next
set Info = nothing

Does anyone have any ideas how to retireve each id?

A second query (but less urgent) is that I can only get this to parse if I remove the outlying square brackets. Why is this and is there a way to parse it with them in?

Many thanks Justin

1条回答
我命由我不由天
2楼-- · 2019-09-13 03:06

Thanks to all those who have taken a look at this problem.

After trying a number of things including reformatting the response on the fly, I've found the rather simple answer to my problem:

For Each key in Info.keys()
    Response.Write Info.get(key).user.id & "<br />"
Next

Hope that helps anyone in the future :-)

查看更多
登录 后发表回答