问题
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