2015-05-08 101 views
1

我應該如何訪問這個JSON中的「遊戲」數組?我正在使用http://aspjson.com的課程。訪問ASP JSON:多維JSON數組

{ 
"period":[ 
    { 
    "period_id":"1774", 
    "start_time_epoch":1431126300, 
    "games":[ 
     { 
      "home_team":"WSH", 
      "away_team":"ATL" 
     } 
    ] 
    } 
] 
} 

方法:

today = date 

For Each key In oJSON.data("period") 
    Set this = oJSON.data("period").item(key) 

    periodID = this.item("period_id") 
    periodDate = FormatDateTime(DateAdd("s", this.item("start_time_epoch"), "01/01/1970 00:00:00"),2) 

    ----Ideally, this.item("games").item("home_team") would have worked.---- 
    if cstr(today) = periodDate then 
     response.write periodID & " - " & periodDate & "<br/> - " & this.item("games").item("start_time") 
    end if 

Next 

回答

1

您的JSON是無效的:http://jsonformatter.curiousconcept.com/

這將是有效的:

{ 
    "period":[ 
     { 
     "period_id":"1774", 
     "start_time_epoch":1431126300, 
     "games":[ 
      { 
       "home_team":"WSH", 
       "away_team":"ATL" 
      } 
     ] 
     } 
    ] 
} 

要訪問主隊可以使用

Response.Write(oJSON.data("period")(0)("games")(0)("home_team")) 
+0

謝謝。我在問題中的JSON被簡化了。 – localhost