MarekLichtoarowicz / vba-json

Automatically exported from code.google.com/p/vba-json
0 stars 0 forks source link

Cannot convert a 2-d array to JSON #8

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a 2-d array, such as: 
Dim arr(0 to 1, 0 to 1) as String
arr(0, 0) = "a"
arr(0, 1) = "b"
arr(1, 0) = "c"
arr(1, 1) = "d"

2. Try to convert to JSON with 
Debug.Print lib.toString(arr)

What is the expected output? What do you see instead?

I expect [["a", "b"], ["c", "d"]]

but I get a "Type Mismatch" error. If I change the array type to Variant, I
get the following: 

[[,],[,]]

but it returns an error.

What version of the product are you using? On what operating system?
json.xls downloaded on 1/15/2010 from the Google Code Site.

Please provide any additional information below.
Thanks for looking into it! 

Original issue reported on code.google.com by mheber...@gmail.com on 15 Jan 2010 at 10:59

GoogleCodeExporter commented 9 years ago
One work-around seems to be to use an array of arrays instead of a 2-d array.
Also, arrays seem to need to be of type Variant for this to work.

So     
    Dim arr(0 To 3) As Variant
    arr(0) = "a"
    arr(1) = "b"
    arr(2) = "c"
    arr(3) = "d"

works.

And 

    Dim arr(1 To 2) As Variant
    arr(1) = Array("a", "b")
    arr(2) = Array("c", "d")

works.

Original comment by walid.na...@gmail.com on 14 Oct 2014 at 7:31