Hey everyone,
For the past couple of days, I have been trying to get GWT to interpret either a JSONValue or a string of XML that gets passed back from the server (using PHP).
I'm pretty frustrated, because I can't seem to get anything to work. For the XML, I have confirmed that the String passed from PHP to GWT is a correct XML string. However, when I try to parse the XML, I get a bunch of null errors.
With the JSON, I get the following from the PHP:
Value: {"item":[{"ID":null, "Primary":null, "Secondary":null, "Date":null, "Region":null},{"ID":null, "Primary":null, "Secondary":null, "Date":null, "Region":null},{"ID":null, "Primary":null, "Secondary":null, "Date":null, "Region":null}]}
I have no idea why the values are NULL, but this is how the GWT looks for the JSON:
public void onChange(Widget sender) {
lb.setText("Date selected: " + calendar.getDate());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String current = df.format(calendar.getDate());
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode("http://www.kbehr.com/calendar/view_duty.php"));
try {
builder.sendRequest(current, new RequestCallback(){
public void onError(Request request, Throwable exception) {
requestFailed(exception);
}
public void onResponseReceived(Request request, Response response) {
String responseText = response.getText();
try {
JSONValue jsonValue = JSONParser.parse(responseText);
processJSON(jsonValue);
} catch (Exception e) {
Window.alert("Error: " + e);
}
}});
}catch (RequestException ex) {
requestFailed(ex);
}
}});
fp.add(calendar);
fp.add(lb);
}
public void processJSON(JSONValue messageXml) {
vp.clear();
vp.add(new Label("Value: " + messageXml));
RootPanel.get("slot2").add(vp);
}
Does anyone know what I am doing wrong with the JSON? I am doing json_encode($array) in the PHP, and I have no idea how to break it down in GWT.
Unfortunately, there aren't many examples online, either...
Thanks!