3

我正在开发一个经典的 ASP 项目,我使用 ASP Xtreme Evolution 来解析 JSon 数据(可在此处找到:http: //zend.lojcomm.com.br/entries/classic-asp-json-revisited/

无论如何...我正确获取了大部分 JSon 数据,但现在我被困在一个数组上。

JSON看起来像这样:

{
  "Product": {
    "ID": "6666",
    "Name": "Tha name",
    "ArticleGroup": [
      {
        "@handleas": "array",
        "Title": "Title 1",
        "Article": {
          "ID": "777",
          "Label": "Label 1",
        }
      },
      {
        "@handleas": "array",
        "Title": "Title 2",
        "Article": {
          "ID": "888",
          "Label": "Label 2",
        }
      }
    ]
    }
  }
}

ASP 看起来像这样:

set xmlHTTP = server.createobject("MSXML2.ServerXMLHTTP.6.0")
xmlHTTP.open "GET", "http://source.of.json", false
xmlHTTP.send()
ProductFeed = xmlHTTP.ResponseText

dim ProductInfo : set ProductInfo = JSON.parse(join(array(ProductFeed)))

    dim key : for each key in ProductInfo.Product.keys()
        Response.Write ProductInfo.Product.ID ' Prints 6666
        Response.Write ProductInfo.Product.Name ' Prints Tha Name
    Next
    set ProductInfo = nothing

我的问题是我无法弄清楚如何访问 ArticleGroup 中的信息。我得到的只是 [object Object]、[object Object] 或空值。

有人有想法么?

谢谢!

4

1 回答 1

3

尝试以下操作(基于给定的 JSON):

Dim ArticleGroup

dim key : For Each key in ProductInfo.Product.keys()
    Response.Write ProductInfo.Product.ID ' Prints 6666
    Response.Write ProductInfo.Product.Name ' Prints Tha Name            

    For Each ArticleGroup In ProductInfo.Product.Get("ArticleGroup") '' iterate all ArticleGroup entries
        Response.write ArticleGroup.Get("Title") '' get the correct key value
    Next
Next

您需要遍历所有 ArticleGroup 条目并通过.get(keyName). 否则它将返回 JScript 函数体。

于 2012-05-08T14:31:26.710 回答