How to handle an array in json format in classic Asp

Asked

Viewed 589 times

0

Well my situation is as follows, I have a variable that brings me the following results:

 var1 = [{"id_item":2,"posicao":1},{"id_item":8,"posicao":2},{"id_item":9,"posicao":3},{"id_item":7,"posicao":4},{"id_item":10,"posicao":5}]

I need to handle this result separately, for example

r1 = id_item
r2 = posicao

how I could get the results of this array separately in the classic Asp,

tried to make a:

teste =  JSON.parse(var1) 

to try to catch the result this way teste.id_item more when I give a Replay.write nothing appears. When I run a Answer.write on the variable test result I am always that.

[object Object],[object Object],[object Object],[object Object],[object Object]

what would be the most correct solution to this problem?

1 answer

1


In Asp I use the Aspjson component http://www.aspjson.com/

See the Reading:

<!--#include virtual="/aspJSON1.17.asp" -->
<%
Set oJSON = New aspJSON

'Carregar a String
oJSON.loadJSON(jsonstring)

'Get valor simples
Response.Write oJSON.data("firstName") & "<br>"

'Percorrer a coleção
For Each phonenr In oJSON.data("phoneNumber")
    Set this = oJSON.data("phoneNumber").item(phonenr)
    Response.Write _
    this.item("type") & ": " & _
    this.item("number") & "<br>"
Next

'Atualizar/Adicionar valores
oJSON.data("firstName") = "James"

'Retornar String Json
Response.Write oJSON.JSONoutput()
%>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.