2012. 12. 11. 19:23


JSON 메시지 생성 (출처 : http://code.google.com/p/aspjson/)

JSON_2.0.4.asp

JSON_UTIL_0.1.1.asp

<!-- #include virtual="JSON_2.0.4.asp" -->

<!-- #include virtual="JSON_UTIL_0.1.1.asp" -->

<%

Dim json

Dim person, people(4)


For i = 0 To 4

Set person = jsObject()

person("name") = "park"

person("age") = 20

person("sex") = "male"

Set people(i) = person

Next


Set json = jsObject()

json("count") = Ubound(people)

json("people") = people


Response.Write toJSON(json)

' 결과

{"count":4,"people":[{"name":"park","age":20,"sex":"male"},{"name":"park","age":20,"sex":"male"},{"name":"park","age":20,"sex":"male"},{"name":"park","age":20,"sex":"male"},{"name":"park","age":20,"sex":"male"}]}

%>


JSON 메시지 파싱 (https://github.com/nagaozen/asp-xtreme-evolution/blob/master/lib/axe/classes/Parsers/json2.asp)

json2.asp

<!-- #include virtual="json2.asp" -->


dim Info : set Info = JSON.parse(join(array( _
    "{", _
    " ""firstname"": ""Fabio"",", _
    " ""lastname"": ""長尾"",", _
    " ""alive"": true,", _
    " ""age"": 27,", _
    " ""nickname"": ""nagaozen"",", _
    " ""fruits"": [", _
    " ""banana"",", _
    " ""orange"",", _
    " ""apple"",", _
    " ""papaya"",", _
    " ""pineapple""", _
    " ],", _
    " ""complex"": {", _
    " ""real"": 1,", _
    " ""imaginary"": 2", _
    " }", _
    "}" _
)))

Response.write(Info.firstname & vbNewline) ' prints Fabio
Response.write(Info.alive & vbNewline) ' prints True
Response.write(Info.age & vbNewline) ' prints 27
Response.write(Info.fruits.get(0) & vbNewline) ' prints banana
Response.write(Info.fruits.get(1) & vbNewline) ' prints orange
Response.write(Info.complex.real & vbNewline) ' prints 1
Response.write(Info.complex.imaginary & vbNewline) ' prints 2

Posted by CoolDragon