rcdmk / aspJSON

A fast classic ASP JSON parser and encoder for easy JSON manipulation to work with the new JavaScript MV* libraries and frameworks.
MIT License
204 stars 89 forks source link

Getting specific parameter #29

Closed coda-apps closed 7 years ago

coda-apps commented 7 years ago

Hi!

Thanks for maintaining this!

I am having an issue getting to a certain parameter (the "name" parameter, below)

    {
       "message":{
          "name":"InternalServerError",  //  this is what i am trying to obtain
          "value":1,
          "text":"לא ניתן לבצע את הפעולה כעת, נסה שנית או פנה למוקד השרות",
          "severity":"E"
       },
       "response":{
          "transactionId":null,
          "fileNumber":0,
          "posNumber":0,
          "posOrdinalNumber":0,
          "cardName":null,
          "cardGradeInAbroad":0
       },
       "tag":null
    }

i assume i need to convert to an array, but it just not working for me:

this is the error:

Response object error 'ASP 0185 : 800a01c2' Missing Default Property /test1/js1.asp, line 0

and this is my code:


dim jsonObj

set jsonObj = new JSONobject
set jsonArr = new jsonArray

set outputObj = jsonObj.parse(jsonString)    ''jsonString is the above string

jsonArr.Push jsonObj

for i = 0 to jsonArr.length - 1
    response.write "Index "
    response.write i
    response.write ": "

    if isObject(jsonArr(i)) then
        set item = jsonArr(i)

        if typeName(item) = "name" then
            item.write()
        else
            response.write item
        end if
    else
        item = jsonArr(i)
        response.write item
    end if

    response.write "<br>"
next

set outputObj = nothing
set jsonObj = nothing
set jsonArr = nothing
rcdmk commented 7 years ago

Hi.

You are dealing with nested objects. In this case you don't need arrays at all.

Try getting the nested object value directly:

jsonObj.parse jsonString

Response.Write jsonObj("message")("name")

Or, if you will need to access more properties from this object, it's best to set it to a variable:

jsonObj.parse jsonString

set message = jsonObj("message")

Response.Write message("name")  & ": " & message("value")

I hope this helps.

coda-apps commented 7 years ago

Ok, got it - thanks!