Looping though JSON classic ASP

若如初见. 提交于 2021-02-10 19:39:31

问题


I am trying to use aspJSON1.17.asp to get data from an JSON file that I am pulling back. ASPJson Site is located here now. http://web.archive.org/web/20160109181310/http://aspjson.com/

The structure of the file is as follows. NOTE: I have truncated here for readability

{
          "@odata.context": "http://trestle.corelogic.com/odata/$metadata#Property/CoreLogic.DataStandard.RESO.DD_1_5.Property",
          "value": [
            {
              "@odata.type": "#CoreLogic.DataStandard.RESO.DD_1_5.Property",
              "AboveGradeFinishedArea": null,
              "AboveGradeFinishedAreaSource": null,
              "AboveGradeFinishedAreaUnits": null,
              "AccessCode": null,
              "AccessibilityFeatures": null,
              "AdditionalParcelsDescription": null,
              "AdditionalParcelsYN": null,
              "AnchorsCoTenants": null,
              "Appliances": null,
              "ApprovalStatus": null,
              "ArchitecturalStyle": null,
              "AssociationAmenities": null,
              "AssociationFee": null,
              "AssociationFee2": null,
              "AssociationFee2Frequency": null,
              "AssociationFeeFrequency": null,
              "AssociationFeeIncludes": null,
              "AssociationName": null,
              "AssociationName2": null,
              "AssociationPhone": null,
              "AssociationPhone2": null,
              "AssociationYN": null,
              "AttachedGarageYN": null,
              "AvailabilityDate": null,
              "Basement": null,
              "BathroomsFull": 10
    }
  ]
}

I have tried the following where pagereturn is the JSON formatted string I am getting back from the API. I am trying to loop though this collection but I cannot get it to work. I keep getting an Object not a collection error.

Here is what I have tried

Set oJSON = New aspJSON
'Load JSON string
oJSON.loadJSON(pageReturn)

'Loop through collection
For Each record In oJSON.data("Property")
    Set this = oJSON.data("Property").item(record)
    Response.Write _
    this.item("bathroomsFull") & "<br> "
Next

AND

'Loop through collection
For Each record In oJSON.data("bathroomsFull")
    Set this = oJSON.data("bathroomsFull").item(record)
    Response.Write _
    this.item("bathroomsFull") & "<br> "
Next

This did not give me an error but I got an empty sting

Response.Write "BathRooms"& oJSON.data("bathroomsFull") & "<br>"

Based on the above I would have thought that I would get "10"

Any help would be appreciated.


回答1:


It’s just a case of understanding the structure of the json, then you can recreate the steps needed to pull the value in code.

The structure appears to be;

object
  property
    collection
      object

So the code should be something like;

Set oJSON = New aspJSON
'Load JSON string
oJSON.loadJSON(pageReturn)

'Loop through collection
For Each record In oJSON.data("value")
  Set this = oJSON.data("value").item(record)
  Response.Write this.item("BathroomsFull") & "<br> "
Next


来源:https://stackoverflow.com/questions/48271242/looping-though-json-classic-asp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!