Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to translate,use JSON in GWT?
    primarykey
    data
    text
    <p>I'm new in gwt. and need to know how to use JSON in gwt so i try this simple data loader but i'm still confuse.<br> I create a project named 'tesdb3' in eclipse. I create the PHP side to access the database, and made the output as JSON..<br> I create the userdata.php in folder war. then I compile tesdb3 project. Folder tesdb3 and the userdata.php in war moved in local server(I use WAMP). I put the PHP in folder tesdb3. This is the result from my localhost/phpmyadmin/tesdb3/userdata.php</p> <pre><code>[{"kode":"002","nama":"bambang gentolet"}{"kode":"012","nama":"Algiz"}] </code></pre> <p>From that result I think the PHP side was working good.<br>Then I create UserData.java as JSNI overlay like this:</p> <pre><code>package com.tesdb3.client; import com.google.gwt.core.client.JavaScriptObject; class UserData extends JavaScriptObject{ protected UserData() {} public final native String getKode() /*-{ return this.kode; }-*/; public final native String getNama() /*-{ return this.nama; }-*/; public final String getFullData() { return getKode() + ":" + getNama(); } } </code></pre> <p>Then Finally in the tesdb3.java:</p> <pre><code>public class Tesdb3 implements EntryPoint { String url= "http://localhost/phpmyadmin/tesdb3/datauser.php"; private native JsArray&lt;UserData&gt; getuserdata(String json) /*-{ return eval(json); }-*/; public void LoadData() throws RequestException{ RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); builder.sendRequest(null, new RequestCallback(){ @Override public void onError(Request request, Throwable exception) { Window.alert("error " + exception); } public void onResponseReceived(Request request, Response response) { //1 //data(getuserdata(response.getText())); //2 JsArray&lt;UserData&gt; uda = JsonUtils.unsafeEval(response.getText()) data(uda); } }); } public void data(JsArray&lt;UserData&gt; data){ for (int i = 0; i &lt; data.length(); i++) { String lkode =data.get(i).getKode(); String lname =data.get(i).getNama(); Label l = new Label(lkode+" "+lname); tb.setWidget(i, 0, l); } RootPanel.get().add(new HTML("my data")); RootPanel.get().add(tb); } public void onModuleLoad() { try { LoadData(); } catch (RequestException e) { e.printStackTrace(); } } } </code></pre> <p>The result from both method i use in the onResponseReceived is the same. Just showing string "my data".<br> but the method 2 create eror like this:<br> 14:41:59.875 [ERROR] [tesdb3] Uncaught exception escaped com.google.gwt.core.client.JavaScriptException: (SyntaxError): syntax error<br><br></p> <p>Did I miss use the 2nd method?<br> Why method 1 didn't have any eror but can't show the data?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload