Thank you very much for your reply. I should've see that sooner.

Just a note to anyone who finds this via a search; make sure your PHP
returns numbers are numbers not quoted strings, otherwise your script
will silently fail when you try to assign your numeric value to a
double.

PHP will automatically enclose all array values in double quotes when
you send the array through json_encode(). To get by that all you need
to do is take all your numeric values out of quotes in the final JSON
string. I used preg_replace($match, "$1", $outputJSONstring).
You can also do the same to replace "null" with "".

Once again thanks for the help.


On Aug 19, 3:19 pm, Thad <[email protected]> wrote:
> The top-level data is not an array.  It's an object with two keys,
> "jewelry" and "metalwork", which contain arrays.  See the diagrams 
> inhttp://www.json.org/
>
> You need to call data.keySet() and iterate through the keys.
>
> On Aug 19, 1:25 pm, Tarek <[email protected]> wrote:
>
> > Hi,
>
> > I'm trying to parse a JSON value returned by my PHP script. The
> > returned JSON string is valid and the project compiles just fine. The
> > problem I'm running into is that JavaScript throws a "(TypeError):
> > data.isArray() is null".
>
> > JavaScript throws that same exception for isTYPE method except for
> > isNull (which returns 'null'). I seem to be missing a step or two in
> > getting GWT to recognize that my JSON string is a multi-dimensional
> > array.
>
> > -- BEGIN JSON String --
> > {
> >     "jewelry": [
> >         {
> >             "ID": "2",
> >             "item": "Minos",
> >             "description": "Inspired by an Ancient Minoan urn.",
> >             "price": "100",
> >             "qty": "1"
> >         },
> >         {
> >             "ID": "4",
> >             "item": "Muse",
> >             "description": null,
> >             "price": "100",
> >             "qty": "1"
> >         }
> >     ],
> >     "metalwork": [
> >         {
> >             "ID": "5",
> >             "item": "Magritte Bowls",
> >             "description": null,
> >             "price": "200",
> >             "qty": "1"
> >         },
> >         {
> >             "ID": "6",
> >             "item": "Poker Fan",
> >             "description": null,
> >             "price": "200",
> >             "qty": "2"
> >         }
> >     ]}
>
> > --END JSON String--
> > Naturally the returned JSON isn't as pretty, but the only thing
> > missing are all the tabs and newlines.
>
> > Here is how I access it:
> > -- BEGIN CODE SNIPPET --
> > //inside the onResponseReceived method
> > if (200 == response.getStatusCode()){
> >         // process the response
> >         JSONValue returnedJSON = JSONParser.parse(response.getText());
> >         PopulateTable(returnedJSON);}//end if
>
> > .
> > .
> > .
> > private void PopulateTable(JSONValue data) {
> >         try {
> >                 // Everything up to this point is works just fine. 
> > Window.Alert
> > statements fire just fine
> >                 JSONArray itemsArr = data.isArray();
> >                 // Anything from the above statement forward doesn't fire 
> > so the
> > exception must be right there.
> >                 .
> >                 .
> >                 .
> >         }//end try
> >         catch (Exception e){
> >                 Window.alert("Caught Excaption: '" + e.getMessage() + "'.");
> >         }//end catch
> > -- END CODE SNIPPET --
>
> > As far as I'm aware; JSONParser returns type JSONValue and the only
> > way to parse that to a JSONArray is the isArray() method. Am I correct
> > in that assumption? If so any idea why it's balking when I try to do
> > it that way?
>
> > Looking forward to your responses.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" 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/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to