티스토리 뷰

https://github.com/rcdmk/aspJSON에서 jsonObject.class.asp 다운로드 받아서 사용

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!-- #include virtual="jsonObject.class.asp" -->
<%
set outputs = new jsonArray
result = array(array("data00""data01""data02""data03""data04"), array("data10""data11""data12""data13""data14"))
 
for each data in result
    set output = new JSONobject
    output.Add "field0", data(0)
    output.Add "field1", data(1)
    output.Add "field2", data(2)
    output.Add "field3", data(3)
    output.Add "field4", data(4)
    outputs.push output
next
 
Response.Write(outputs.Write()&"<br/>")
 
function selectionSortArray(arrShort, ascFlag, sortSize)
    arrShortSize = UBound(arrShort) + 1
    for i = 0 To arrShortSize-2 Step 1
        if i < sortSize then
            for j = i+1 to arrShortSize-1 step 1
                if ascFlag then
                    if arrShort(i) > arrShort(j) then
                        temp=arrShort(i)
                        arrShort(i)=arrShort(j)
                        arrShort(j)=temp
                    end if
                else
                    if arrShort(i) < arrShort(j) then
                        temp=arrShort(i)
                        arrShort(i)=arrShort(j)
                        arrShort(j)=temp
                    end if
                end if
            next
        else
            exit for
        end if
    next
    selectionSortArray = arrShort
end function
 
Function sortingJsonArrayByKey(unsortedArr, keyNames, sortKey, ascFlag, sortSize)
    Dim k, l, m, n
    Dim temp
    Dim aLen
    Dim tempArr()
    Set sortedArr = new jsonArray
    aLen = unsortedArr.length
    For k = 0 To aLen-1 Step 1
        ReDim Preserve tempArr(k)
        tempArr(k) = unsortedArr(k).Value(sortKey)
        unsortedArr(k).Add "_sortIndex"False
        'response.write(tempArr(k)&"<br/>")    
    Next
    sortedValueArr = selectionSortArray(tempArr, ascFlag, sortSize)
    'sortedValueArr = bubbleSortArray(tempArr, ascFlag)
    For l = 0 To aLen-1 Step 1
        if l < sortSize then
            for m = 0 to aLen-1 step 1
                if sortedValueArr(l) = unsortedArr(m).Value(sortKey) and unsortedArr(m).Value("_sortIndex"= False then
                    sortedArr.push unsortedArr(m)
                    unsortedArr(m).Change "_sortIndex"True
                    exit for
                end if
            next
        else
            exit for
        end if
    Next
    For n = 0 To sortedArr.length-1 Step 1
        sortedArr(n).Change "_sortIndex", n
    Next
    set sortingJsonArrayByKey = sortedArr
End Function
 
set rev_sorted_by_field4_value_output = sortingJsonArrayByKey(outputs, array("field0""field1""field2""field3""field4"), "field0"False2)
 
Response.Write(rev_sorted_by_field4_value_output.Write()&"<br/>")
%>
cs


출력 : 

1
2
[{"field0":"data00","field1":"data01","field2":"data02","field3":"data03","field4":"data04"},{"field0":"data10","field1":"data11","field2":"data12","field3":"data13","field4":"data14"}]
[{"field0":"data10","field1":"data11","field2":"data12","field3":"data13","field4":"data14","_sortIndex":0},{"field0":"data00","field1":"data01","field2":"data02","field3":"data03","field4":"data04","_sortIndex":1}]
cs


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
페이지
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함