我对 JSON 和 GWT 还是很陌生,我正在尝试弄清楚如何将 JSON 数据从页面传回我的 GWT 应用程序。我将 JSON 传递回一个类:
public class GetProductTree extends JavaScriptObject {
protected GetProductTree() { }
public final native String getCustomerName() /*-{ return this.customername; }-*/;
}
这是非常基本的,目前还不完整,所以我只是(现在)尝试确保我能拿回一些东西。
调用它的代码是:
submitProject.addClickListener(new ClickListener() {
public void onClick(Widget w) {
RequestBuilder.Method method=RequestBuilder.GET;
final String url1 = "http://localhost:8500/getProducts.cfm";
//Window.alert(url1);
RequestBuilder rb = new RequestBuilder(method, url1);
try {
rb.sendRequest(null, new RequestCallback() {
public void onResponseReceived(Request request, Response response) {
JSONObject oResults = (JSONObject) JSONParser.parse(response.getText());
GetProductTree oResponse = oResults.isObject().getJavaScriptObject().cast();
Window.alert(oResponse.getCustomerName());
}
public void onError(Request arg0, Throwable arg1) {
Window.alert("error");
}
});
} catch (RequestException e) {
}
}
});
但是我收到一个错误:
没有可用于类型 XYZ.GetProductTree 的源代码;你忘了继承一个必需的模块吗?
我正在调用页面上为 XYZ.GetProductTree 导入正确的包。我错过了什么?