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の情報にアクセスする方法がわからないことです。私が得るのは[オブジェクトオブジェクト]、[オブジェクトオブジェクト]または空の値だけです。

誰かアイデアはありますか?

ありがとう!

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 に答える