Hi Gregory
Your wild guess got me to a working result:
JSONArray jsonArray = new JSONArray(json);
Collection data = JSONArray.toList(jsonArray, HashMap.class);
I have not tried this yet, but I would guess that when I have more nested data,
things will probably fail on me again, e.g.
[{"description": "Dinner", "price": {"amount": "25.85", "currency": "USD"},
"dates": ["2010-02-06", "2010-02-10", "2010-02-28"]}]
But for now my problem is solved and I can say: Thanks + good night.
-will
On 11.02.2010, at 01:09, Grégory Joseph wrote:
>
>
> On Feb 11, 2010, at 12:28 AM, Will Scheidegger wrote:
>
>>
>> Dear Magnolians
>>
>> I'm currently working on a custom control which posts a JSON string to the
>> dialog save handler - a list of objects, e.g.
>>
>> [{"description": "Dinner", "price": "25.85", "date": "2010-02-10"},
>> {"description": "Train ticket", "price": "48.2", "date": "2010-02-10"},
>> {"description": "Solution to JSON problem", "price": "priceless"}]
>>
>> The custom control works fine and JavaScript has now problems turning this
>> String into an array of objects. Unfortunately I have not found an easy way
>> to do the same with
>
>
>> the json-lib which comes with Magnolia.
>
> http://json-lib.sourceforge.net/
>
>> All I would like to do is to simply convert the string above into a
>> Collection object containing three Map objects. Maybe I'm missing something
>> obvious (easily possible since it's been a long day) or this json-lib does
>> not make thinks as easy as they could be. So any pointers are warmly
>> appreciated!
>
> Wild guess, something along the lines of
> final JSONObject json = new JSONObject(jsonString);
> return (Collection) JSONObject.toBean(json, Collection.class);
>
> .. you could also try the static fromObject() methods with your expected
> result, to see the kind of string this will give you.
>
> Cheers,
>
> -g
>
>
>
>
> ----------------------------------------------------------------
> For list details see
> http://www.magnolia-cms.com/home/community/mailing-lists.html
> To unsubscribe, E-mail to: <[email protected]>
> ----------------------------------------------------------------
>
----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------