[json-lib-user] json string to javabean, parsing array into property issue.
Brought to you by:
aalmiray
From: stuart m. <stu...@ho...> - 2009-03-03 17:42:02
|
I'm trying to parse a JSON string into/from a bean's property. It works fine, except for mapping an array[][][] to a property. Using a sample piece of JSON, adding a subelement e.g. circles, has me stumped. How do I get the array into the bean's property? Ideally, the property holding the array "circles" would be an arrayList or array of circles, with inner circles and finally point objects. How do I achieve this? I couldn't see how to achieve this. Stub code below. Thanks, Stuart JSONObject jsonObjectMyBean = (JSONObject) JSONSerializer.toJSON( sampleJSONString ); JsonConfig jsonConfigMyBean = new JsonConfig(); jsonConfigMyBean.setRootClass( MyBean.class ); MyBean MyBean= (MyBean) JSONSerializer.toJava( jsonObjectMyBean, jsonConfigMyBean); MyBean { String type; String name; String classType; (?unknown type) Object Circles - It's an Object circles; //it comes through as an arraylist<object> with two inner arraylists. Drilling into the first element is an arraylist<Object> it has [[98.4375,-45],[99.140625,-49.5703125]], the next arraylist has [98.4375, -45], so item 0 is 98.4 etc. //suitable getters/setters } the sample jsonString is { "type": "geometry", "circles": [ //e.g. circles0 [ //e.g circle0 [ //e.g. point0 98.4375, -45.90 ], [ 99.140625, -49.5703125 ] ] ], "name": "test_name", "classType": "className" } _________________________________________________________________ 25GB of FREE Online Storage – Find out more http://clk.atdmt.com/UKM/go/134665320/direct/01/ |