1

我有一个模型,例如波纹管。

public class ColumnDtoWrapper extends JavaScriptObject{

protected ColumnDtoWrapper() {}

public final native JsArray<ColumnDto> getfields() /*-{
    return this.fields;
}-*/;

public final native void gettable() /*-{
return this.table;
}-*/;

public final native JavaScriptObject getHasMany() /*-{
    return this.hasmany;
}-*/;
}

我像这样进行服务器调用

RequestBuilder build = new RequestBuilder(RequestBuilder.POST, URL);
    try {
        Request request = build.sendRequest(null, new RequestCallback(){
            @Override
            public void onResponseReceived(Request request, Response response) {
                if(200== response.getStatusCode()){

                    }
                }

            @Override
            public void onError(Request request, Throwable exception) {
                Window.alert("error : " + exception.getLocalizedMessage());
            }

        });
    } catch (Exception e) {
        Window.alert("try err");
    }

当我在 JSON 字符串中获得成功响应时。我想将该字符串转换为 ColumnsDtoWrapper。

类似 ColumnDtoWrapper col = new ColumnDtoWrapper(responce.getText());

但它不起作用有什么好方法可以将字符串转换为 JavaScriptObject 吗?

4

1 回答 1

2

使用JsonUtils.safeEval

ColumnDtoWrapper col = JsonUtils.safeEval(response.getText());
于 2012-09-16T17:22:11.607 回答