Hey Sagar,
I tried using it
But i am facing a problem in it.
I have a class say

class abc
{

       public String id;
       public String ver;


}
class pqr
{
  public String lmn;
  public String xyz;
}
class holder
{
 public Object [] params;

}

public void method()
{
  abc aobj = new abc("1","a");

  pqr pobj = new pqr("a","b");
  gson = new Gson();
  jsonstr = gson.toJson(pobj);
  Log.i("Output is ",""+jsonstr);
  holder hold = new holder();
  hold.params = new Object[2];
  hold.params[0] = aobj;
  hold.params[1] = pobj;
  gson = new Gson();
  jsonstr = gson.toJson(hold);
  Log.i("Output is ",""+jsonstr);
}

Output
{"lmn":"a","xyz":"b"}
{"params":[{},{}]}
So if i have a user defined object as a ref of another object, it doesnt
serialise it i suppose.
If i do
gson = new Gson();
  jsonstr = gson.toJson(hold.params[0]);
It gives the output perfectly.So its getting assigned

I have posted this question on Gson  forum but  with no response.
I hope someone knows the answer. I tried using Xstream but its giving me
some exceptions while running the program. In  Xstream  they hv mentioned
that Json object cannot hold references so i think it must be the same
problem with Gson.
Sorry for posting too much on Json, but i want an urgent solution.

Has anyone succesfully tried using ang good Json library on  android , if
yes please gc me directions on it.
Thanks in adv.
Alok.

On Fri, Sep 11, 2009 at 9:45 AM, sagar <[email protected]> wrote:

>
> Hi Alok,
>
> Use Gson.. It is a google library for converting gson response
> directly to the class objects. Just google it and use..
>
> On Sep 9, 11:51 pm, Alok Kulkarni <[email protected]> wrote:
> > Thanks mark for your quick response. Regarding the get and put methods ,
> i
> > am using them currently . But it would hv been great if i could read the
> > entire response in an object like the third party  support .. Anyways
> > nothing comes easily. I will have a look at the Jettison driver and post
> the
> > solution when i have it.
> > Thanks and Regards,
> > Alok.
> >
> > On Wed, Sep 9, 2009 at 10:01 PM, Mark Murphy <[email protected]
> >wrote:
> >
> >
> >
> >
> >
> > > Alok wrote:
> > > >       Some way to put the myClassObj in JSONObject and send it to
> server.
> >
> > > JSON works with arrays and "objects" (roughly a HashMap), not custom
> > > classes.
> >
> > > So, if you want to put stuff in a JSONObject, you have to do it
> yourself
> > > via put() method calls.
> >
> > > >       On retreival i should be able to assign JSONObject to MyClass
> > > object
> > > > and all values such as code , message should be automatically
> > > > retrievable
> >
> > > Use get() on the JSONObject.
> >
> > > > I have seen some dot net examples whering serialization /
> > > > deserialization has been done to objects . How can i do it here?
> >
> > > This has nothing to do with Android and everything to do with the
> > > JSON.org third-party library integrated in by Android.
> >
> > > A quick Google search for:
> >
> > > java jsonobject
> >
> > > turned up:
> >
> > >http://java-x.blogspot.com/2007/04/using-json-from-java.html
> >
> > >http://stackoverflow.com/questions/944285/how-to-create-a-json-object.
> ..
> >
> > > --
> > > Mark Murphy (a Commons Guy)
> > >http://commonsware.com|http://twitter.com/commonsguy
> >
> > > _The Busy Coders' Guide to *Advanced* Android Development_ In Print!
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to