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
-~----------~----~----~----~------~----~------~--~---