A JSONObject basically is a bean. It's a pretty sophisticated Map. I
do similar stuff to you, but I don't fool with Beans.

I encapsulated my web service as a content provider. It communicates
to me with JSONObjects, and JSONObjects packaging JSONArrays. I get
the JSON string and parse it in the ContentProvider, then return a
custom Cursor-derived object that holds onto the JSONObject, and its
subcomponents, and does all the Cursor operations. So I never need to
copy any data, like what you're doing with your beans in the example
above.

I looked at the code and am not sure it would be that helpful to you.
If you want, I'll post it.

On Jan 15, 3:19 am, Bert <[email protected]> wrote:
> I'm using HttpClient to get the response of a webservice (REST
> servlet) which is a JSON string.
> This string represents a JSONArray of type Map with key "mybeans".
> I'd like to assemble my bean using the JSON string.
> Usually I use net.sf.json json-lib and do something like this:
>
> String s = jsonStringIGotFromResponse;
> Map<String, List> bean = (Map<String, List>) JSONObject.toBean(
>                                 JSONObject.fromObject(s), Map.class);
> List myBeans = bean.get("mybeans");
> JSONArray jsonArray = JSONArray.fromObject(myBeans);
> List<MyBean> myBeansToReturn = new ArrayList<MyBean>();
> for (int i = 0; i < jsonArray.size(); i++) {
>         JSONObject jsonObject = jsonArray.getJSONObject(i);
>         MyBean myBean = (MyBean)JSONObject.toBean(jsonObject,
>                         MyBean.class);
>         myBeansToReturn.add(myBean);
>
> }
>
> I have no idea how to write something similar using the org.json
> classes provided by the Android.jar
>
> Could anyone help me out with this please?
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to