开发者

converting VBA array to a JSON array

I am str开发者_运维百科uggling to convert an array in VBA to JSON. Most of the info on the internet is for the reverse. Has anyone done this before? Do you still have the function?

I need to take an associative array in VBA (excel) and convert it to JSON so I can use it in javascript on my site.

Structure

cars ['BMW'][0]['model'] = 'Series 5'
cars ['BMW'][0]['year'] = 2000
cars ['BMW'][0]['shape'] = 'hatch'
cars ['BMW'][0]['doors'] = 5
cars ['BMW'][1]['model'] = 'Series 3'
......


Javascript array of object literals:

   [{make:'BMW',model:'Series 5',year:2000,shape:'hatch',doors:5},
    {make:'BMW',model:'Series 3',year:2001,shape:'hatch',doors:5}]

Possible JSON equivalent:

    {"cars":[{"make":"BMW","model":"Series 5","year":2000,"shape":"hatch","doors":5},
     {"make":"BMW","model":"Series 3","year":2001,"shape":"hatch","doors":5}]}

Unless you're asking a different question?


Assuming this is an Excel Spreadsheet with rows and columns, your JSON structure will look something like.

[[r1c1, r1c2, r1c3, r1c4, r1c5],
 [r2c1, r2c2, r2c3, r2c4, r2c5],
 [r3c1, r3c2, r3c3, r3c4, r3c5],
 [r4c1, r4c2, r4c3, r4c4, r4c5],
 [r5c1, r5c2, r5c3, r5c4, r5c5]]

This assumes you have 5 rows and 5 columns. (r1c1 is the cell at row1,column1)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜