循环虽然JSON经典ASP

时间:2018-01-15 22:00:03

标签: json asp-classic

我正在尝试使用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格式字符串。我试图循环这个集合,但我无法让它工作。我一直得到一个Object而不是一个集合错误。

这是我试过的

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

这没有给我一个错误,但我得到一个空的刺痛

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

基于以上所述我会认为我会得到“10”

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

只是理解json的结构,然后你可以重新创建在代码中提取值所需的步骤。

结构似乎是;

object
  property
    collection
      object

所以代码应该是这样的;

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