2
在過去的幾天,我一直在試圖讓GWT解釋無論是JSONValue或會從服務器(使用PHP)傳遞迴XML字符串。挫折解析XML或JSON用GWT
我很沮喪,因爲我似乎無法得到任何工作。對於XML,我已經確認從PHP傳遞給GWT的字符串是正確的XML字符串。但是,當我嘗試解析XML時,出現一堆空錯誤。
隨着JSON,我從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}]}
我不知道爲什麼值是NULL,但這是GWT的外觀爲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);
}
有誰知道我在做什麼錯的JSON?我做json_encode($陣列)在PHP,我不知道如何打破它在GWT。
不幸的是,網上沒有太多例子,要麼...
謝謝!