2012-09-16 35 views
1

我有一個模型,如波紋管。GWT創建JAVAscriptObject表單字符串

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。

somthing like ColumnDtoWrapper col = new ColumnDtoWrapper(responce.getText());

但它不起作用有沒有什麼好的方法將字符串轉換爲JavaScriptObject?

回答

2

JsonUtils.safeEval使用:

ColumnDtoWrapper col = JsonUtils.safeEval(response.getText()); 
+0

我採用以下way.'public靜態最終天然ŤGETRESPONSE(字符串responseString)/ * - { \t返回的eval( '(' + responseString + ')'); \t} - * /;' –