简体   繁体   中英

Parse JSON on Classic ASP

How can I get the a JSON Array I get using ASPJSON v1.17 or json2.asp .

[
  {
    "id":1,
    "children":[
      {"id":2},
      {
        "id":7,
        "children":[
          {
            "id":8,
            "children":[
              {"id":9}
            ]
          }
        ]
      }
    ]
  },
  {
    "id":3,
    "children":[
      {"id":11},
      {"id":12},
      {"id":13},
      {"id":14},
      {"id":15}
    ]
  },
  {
    "id":4,
    "children":[
      {"id":16},
      {"id":17},
      {"id":18}
    ]
  },
  {
    "id":5,
    "children":[
      {"id":19},
      {"id":20}
    ]
  },
  {"id":6}
]

How to iterate through each member in the loop?

I've experimented with vbs libraries for json and I've come to the conclusion that it's much easier to use js as your scripting language when you're handling json. I say that as someone who hates js (whether server or client side) and generally avoids using it whenever possible.

Anyway - a very simple example

<%@language="javascript"%>
<!DOCTYPE html>
<html>
<body>
<h2>JSON ASP Javascript example</h2>
<%
var cars = [{name:'Aston Martin', colour:'Blue'}, {name:'Jaguar', colour:'Silver'}, {name:'Bentley', colour:'Green'}];
for (i in cars)
{ %>
  <%=(cars[i].name) %>, <%=(cars[i].colour) %> <br />
<% } %>

</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM