SEMSEM123 / aspjson

Automatically exported from code.google.com/p/aspjson
0 stars 0 forks source link

ToJSON(array) splits array indexes #1

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Code snippet:

a = Array()
' ol.List contains ~25 items
For Each x In ol.List
    ReDim Preserve a(UBound(a)+1)
    Set a(UBound(a)) = JSObject()
    a(UBound(a))("id") = ol.List(x).id
    a(UBound(a))("name") = ol.List(x).name
Next

ToJSON(a) contains 10 full items, others are just commas.

The problem is in this code:
For i = 1 To Len(sPB1)
    If i <> 1 Then sPB2 = sPB2 & ","
    sPB2 = sPB2 & Mid(sPB1, i, 1)
Next
MultiArray = MultiArray & toJSON(Eval("aBD(" & sPB2 & ")"))

We didn't got why is this code here, but it splits array index 10 into two-
dimensional index 1,0 and so on, so the contents of the indexes 10 and 
more is eaten by this code :)

We've just commented the code to this state to solve the problem:
If Err = 9 Then
    sPB1 = sPT & sPS
'   For i = 1 To Len(sPB1)
'       If i <> 1 Then sPB2 = sPB2 & ","
'       sPB2 = sPB2 & Mid(sPB1, i, 1)
'   Next
    MultiArray = MultiArray & toJSON(Eval("aBD(" & sPB1 & ")"))
    prw MultiArray 

Original issue reported on code.google.com by umaxfun on 9 Jul 2008 at 9:36

GoogleCodeExporter commented 8 years ago
"prw MultiArray " in my post is just our debug string, do not pay attention to 
it, 
please :)

Original comment by umaxfun on 9 Jul 2008 at 9:42

GoogleCodeExporter commented 8 years ago
Isn't correct issue. Use jsArray().

{{{
' *** ol.List PERSONIFICATION ***
Class SampleItem
    Public Id
    Public Name
End Class

Dim i, List(25)
For i = 0 To 25
    Set List(i) = new SampleItem
    List(i).Id = i
    List(i).Name = "person " & i
Next
' *** ol.List PERSONIFICATION ***

' List aka ol.List
Set a = jsArray()
For Each x In List
    Set a(Null) = jsArray()
    a(Null)("id") = x.Id
    a(Null)("name") = x.Name
Next

a.Flush ' Response.Write toJSON(a)
}}}

Original comment by tugrulto...@gmail.com on 14 Jul 2008 at 10:05

GoogleCodeExporter commented 8 years ago
Oh! I didn't ever see this - "a(Null)", furthermore I do not get why am I 
wrong, but 
thanks, tomorrow I'll try your solution. Nevertheless, thanks for your comment. 
I'm 
sure I'm not the first and not the last to come into this trouble, sure it 
helps :)

Original comment by umaxfun on 14 Jul 2008 at 10:23