循环 JSON 经典 ASP
Looping though JSON classic ASP
我正在尝试使用 aspJSON1.17.asp 从我正在撤回的 JSON 文件中获取数据。 ASPJson 站点现在位于此处。
http://web.archive.org/web/20160109181310/http://aspjson.com/
文件结构如下。注意:为了便于阅读,我在此处进行了截断
{
"@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
}
]
}
我尝试了以下方法,其中 pagereturn 是我从 API 返回的 JSON 格式的字符串。我试图遍历这个集合,但我无法让它工作。我一直收到对象不是集合错误。
这是我试过的
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
和
'Loop through collection
For Each record In oJSON.data("bathroomsFull")
Set this = oJSON.data("bathroomsFull").item(record)
Response.Write _
this.item("bathroomsFull") & "<br> "
Next
这并没有给我一个错误,但我得到了一个空的 sting
Response.Write "BathRooms"& oJSON.data("bathroomsFull") & "<br>"
基于以上我以为我会得到“10”
如有任何帮助,我们将不胜感激。
只是了解了json的结构,然后就可以在代码中重新创建拉取值所需的步骤了。
结构似乎是;
object
property
collection
object
property
所以代码应该是这样的;
Set oJSON = New aspJSON
'Load JSON string
oJSON.loadJSON(pageReturn)
'Loop through collection
For Each record In oJSON.data("value")
'Object Reference within the Array.
Set this = oJSON.data("value").item(record)
'Use the Object Reference to access it's properties.
Response.Write this.item("BathroomsFull") & "<br> "
Next
我正在尝试使用 aspJSON1.17.asp 从我正在撤回的 JSON 文件中获取数据。 ASPJson 站点现在位于此处。 http://web.archive.org/web/20160109181310/http://aspjson.com/
文件结构如下。注意:为了便于阅读,我在此处进行了截断
{
"@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
}
]
}
我尝试了以下方法,其中 pagereturn 是我从 API 返回的 JSON 格式的字符串。我试图遍历这个集合,但我无法让它工作。我一直收到对象不是集合错误。
这是我试过的
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
和
'Loop through collection
For Each record In oJSON.data("bathroomsFull")
Set this = oJSON.data("bathroomsFull").item(record)
Response.Write _
this.item("bathroomsFull") & "<br> "
Next
这并没有给我一个错误,但我得到了一个空的 sting
Response.Write "BathRooms"& oJSON.data("bathroomsFull") & "<br>"
基于以上我以为我会得到“10”
如有任何帮助,我们将不胜感激。
只是了解了json的结构,然后就可以在代码中重新创建拉取值所需的步骤了。
结构似乎是;
object
property
collection
object
property
所以代码应该是这样的;
Set oJSON = New aspJSON
'Load JSON string
oJSON.loadJSON(pageReturn)
'Loop through collection
For Each record In oJSON.data("value")
'Object Reference within the Array.
Set this = oJSON.data("value").item(record)
'Use the Object Reference to access it's properties.
Response.Write this.item("BathroomsFull") & "<br> "
Next