Have a look at ArrayReader class. It might help.
- Avadh
On Fri, Nov 14, 2008 at 4:16 PM, Brian H. Mayo <[EMAIL PROTECTED]>wrote:
>
> Here is a sample of the JSON I am trying to read:
> {"version":1,"recipe":[{"id":"1","title":"Nastia's Roasted Unstuffed
> Turkey","description":"As a foreign exchange student, I was invited
> for Thanksgivings and Christmas dinners by more than 20 different
> American
> families","skill":"Intermediate","nationality":"American","dishtype":"Main
> Course","servings":"6","author":"bhsmith","created_at":"2008-11-06
> 00:18:52","ingredients":["ingr 1","ingr 2","ingr 3"]}]}
> ** consider that ingredients can have a variable number of items in
> the array
>
> Here is the code I am working with:
> ----------------
> final RecordDef recordDef = new RecordDef(new FieldDef[]{
> new IntegerFieldDef("id"),
> new StringFieldDef("title"),
> new StringFieldDef("description"),
> new StringFieldDef("skill"),
> new StringFieldDef("nationality"),
> new StringFieldDef("dishtype"),
> new IntegerFieldDef("servings"),
> new StringFieldDef("author"),
> new DateFieldDef("created_at", "created_at",
> "timestamp")
> ?????????????????????????
> });
> JsonReader reader = new JsonReader(recordDef);
> reader.setRoot("recipe");
> // reader.setId("id");
>
> DataProxy dataProxy = new ScriptTagProxy("http://localhost/
> test_feed/getrecipe.php <http://localhost/test_feed/getrecipe.php>");
> final Store store = new Store(dataProxy, reader, false);
> ----------------
> I put ? marks where I need to put something I am just not sure what.
> What type of FieldDef can I use to describe the JSON object that is
> actually an array of strings?
>
> Thanks.
>
> On Nov 14, 11:31 am, "avadh patel" <[EMAIL PROTECTED]> wrote:
> > As I understood your problem correctly you want to have an Array in JSON
> and
> > retrieve that array on the client side. If you are using GWT's JSON
> methods,
> > they provide JSONArray class. So when you parse the object and call
> > 'isArray()' function it returns an array that can have variable size of
> > elements into it.
> > In this array each element can be of any type so that you can have mix of
> > multiple things like string as title and then intetger showing the length
> of
> > that title etc.
> >
> > - Avadh
> >
> > On Fri, Nov 14, 2008 at 11:24 AM, Brian H. Mayo <[EMAIL PROTECTED]
> >wrote:
> >
> >
> >
> > > I am building a small application that deals with Compact Discs (CDs).
> > > There is a grid that gets and displays a few pieces of CD information:
> > > id, title, artist.
> > > When a user clicks on a row, a form will populate with the details of
> > > the CD for the user to edit and submit back.
> > > The data comes from a JSON feed created in PHP.
> >
> > > The rub here is that a CD (an album) can have a variable number of
> > > tracks. Thus, the JSON coming back will have fixed fields like title,
> > > artist, year, etc. but will also have a field called tracks that will
> > > contain a variable number of string values.
> >
> > > How can I code the form and feed retrieval so that when a user clicks
> > > a row I can make the JSON request and populate a structure with the
> > > assumption that I will have a tracks object that contains a variable
> > > number of strings? My (little) experience hows that I must define the
> > > record definition ahead of time before pulling the data from the feed
> > > and while I see a StringRecordDef type and an IntegerRecordDef type, I
> > > see nothing that allows for an array of values.
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"GWT-Ext Developer Forum" 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/gwt-ext?hl=en
-~----------~----~----~----~------~----~------~--~---