2014-07-26 59 views
0

使用http://www.aspjson.com/https://github.com/nagaozen/asp-xtreme-evolution/blob/master/lib/axe/classes/Parsers/json2.asp對象我設法讓我的數據從URL到字典對象。但我試過了,並且想不到使用aspjson從「開放」對象中獲取數據的方式:-(我還沒有設法找到使用json2.asp庫來獲取任何數據的方法,以下是我的數據:如何使用json2.asp或aspjson庫訪問傳統ASP中的JSON數據?

{ 
"restaurant": { 
    "id": 6, 
    "email": "[email protected]", 
    "visiblemail": "1", 
    "date": "2014-07-24 07:38:59", 
    "logo": "818_294.png", 
    "img": "818_554|818_558|818_563", 
    "opening": { 
     "sun": [ 
      "closed" 
     ], 
     "mon": [ 
      "10.00", 
      "20.00" 
     ], 
     "tue": [ 
      "10.00", 
      "20.00" 
     ], 
     "wed": [ 
      "10.00", 
      "20.00" 
     ], 
     "thu": [ 
      "10.00", 
      "20.00" 
     ], 
     "fri": [ 
      "10.00", 
      "20.00" 
     ], 
     "sat": [ 
      "closed" 
     ], 
     "hol": [ 
      "zaprto" 
     ] 
    }, 

    "timetable": null 
} 

}

我知道這兩個庫使用字典對象來存儲數據,但我失去了我如何從對象檢索數據。

回答

4

可以使用isObject檢查,看是否元素有內部成員

包含文件使用是從你給的鏈接

<!--#include file="aspJSON1.17.asp" --> 
<% 
Set oJSON = New aspJSON 
jsonstring = "{ "&_ 
"""restaurant"": {"&_ 
    """id"": 6,"&_ 
    """email"": ""[email protected]"","&_ 
    """visiblemail"": ""1"","&_ 
    """date"": ""2014-07-24 07:38:59"","&_ 
    """logo"": ""818_294.png"","&_ 
    """img"": ""818_554|818_558|818_563"","&_ 
    """opening"": {"&_ 
    " ""sun"": ["&_ 
    "  ""closed"""&_ 
    " ],"&_ 
    " ""mon"": ["&_ 
    "  ""10.00"","&_ 
    "  ""20.00"""&_ 
    " ],"&_ 
    " ""tue"": ["&_ 
    "  ""10.00"","&_ 
    "  ""20.00"""&_ 
    " ],"&_ 
    " ""wed"": ["&_ 
    "  ""10.00"","&_ 
    "  ""20.00"""&_ 
    " ],"&_ 
    " ""thu"": ["&_ 
    "  ""10.00"","&_ 
    "  ""20.00"""&_ 
    " ],"&_ 
    " ""fri"": ["&_ 
    "  ""10.00"","&_ 
    "  ""20.00"""&_ 
    " ],"&_ 
    " ""sat"": ["&_ 
    "  ""closed"""&_ 
    " ],"&_ 
    " ""hol"": ["&_ 
    "  ""zaprto"""&_ 
    " ]"&_ 
    "},"&_ 
    """timetable"": null"&_ 
"}" 


'Load JSON string 
oJSON.loadJSON(jsonstring) 

set restaurant = oJSON.data("restaurant") 

for each itm in restaurant 
    if Not IsObject(restaurant.item(itm)) then 
     Response.write itm &" : "& restaurant.item(itm) & "<br/>" 
    else 
    'opening 
     for each dayy in restaurant.item(itm) 
      Response.write dayy & ":" 
       Response.write restaurant.item(itm)(dayy)(0) 

       If restaurant.item(itm)(dayy)(1) <> "" Then 
        Response.write " - " 
        Response.write restaurant.item(itm)(dayy)(1) 
       End If 

      Response.write "<br/>" 
     next 
    end if 


next 




%> 
+0

偉大的作品,這是我所需要的,我無法弄清楚如何迭代通過嵌套的對象:-( – Jerry2