java - GWT with type overlay for twitter search results -


i trying adapt gwt tutorial making requests json data on site grab search results twitter (http://code.google.com/webtoolkit/doc/latest/tutorial/xsite.html). cannot figure out how adapt overlay type fit twitter results come as:

{"results":[  {"text":"@twitterapi  http:\/\/tinyurl.com\/ctrefg",  "to_user_id":396524,  "to_user":"twitterapi",  "from_user":"jkoum",  "id":1478555574,     "from_user_id":1833773,  ... 

(http://apiwiki.twitter.com/twitter-search-api-method%3a-search)

so results array of objects of sort need read java program. trying write overlay class, couldn't figure out how parse results array bit because i'm not sure type supposed be.

package com.google.twentynumbers.client;  import com.google.gwt.core.client.javascriptobject;  public class twitterresults extends javascriptobject {      protected twitterresults() { }      public final native string getresults() /*-{ return this.results; }-*/;     public final native string gettouser() /*-{ return this.to_user_id; }-*/; } 

i tried writing getresults() return this.results[0].to_user_id; (just see if read 1 of inner fields, not work).

for reference trying read data way:

     /**   * cast javascriptobject jsarray of stockdata.   */  private final native jsarray<twitterresults> asarrayofresultdata(javascriptobject jso) /*-{     return jso;  }-*/;   /**   * handle response request stock data remote server.  */  private void handlejsonresponse(javascriptobject tweets) {     if (tweets == null) {       displayerror("couldn't retrieve json");       return;     }      jsarray<twitterresults> results = asarrayofresultdata(tweets);     displayerror(results.get(0).getresults());   } 

thanks help.

edit on 1/17/2010:

here additional code. window.alert call above [3] produces proper alert e.g. ("the page says 787304

/** * cast javascriptobject class twitterresults */ private final native twitterresults asarrayofresultdata(javascriptobject jso) /*-{  return jso; }-*/;   /**    * handle response request twitter data remote server.    */   private void handlejsonresponse(javascriptobject tweets) {     /*if (tweets == null) {       displayerror("couldn't retrieve json");       return;     }*/      twitterresults tw = asarrayofresultdata(tweets);      displayerror(tw.getmaxid()); // here 'null'   }   /**    * make call remote server.    */   public native static void getjson(int requestid, string url, twentynumbers handler) /*-{    var callback = "callback" + requestid;     // [1] create script element.    var script = document.createelement("script");    script.setattribute("src", url + callback);    script.setattribute("type", "text/javascript");     // [2] define callback function on window object.    window[callback] = function(jsonobj) {     window.alert(jsonobj.max_id); // here alerts correct value    // [3]      handler.@com.google.twentynumbers.client.twentynumbers::handlejsonresponse(lcom/google/gwt/core/client/javascriptobject;)(jsonobj);      window[callback + "done"] = true;    } ...  /* file: twitterresults.java */  package com.google.twentynumbers.client;  import com.google.gwt.core.client.javascriptobject;  public class twitterresults extends javascriptobject {      protected twitterresults() { }      //public final native string getresults() /*-{ return this.results[0].to_user_id; }-*/;     public final native string getsinceid() /*-{ return this.since_id; }-*/;     public final native string getmaxid() /*-{ return this.max_id; }-*/;     //public final native string gettouser() /*-{ return this.to_user_id; }-*/; } 

okay, got it.

the key careful type java code being handed json object / javascript. if don't cast this.max_id string attempts pass javascript "number" class java has no idea with.

here working overlay class (with additional tweet overlay class)

package com.google.twentynumbers.client;  import com.google.gwt.core.client.javascriptobject; import com.google.gwt.core.client.jsarray;  public class twitterresults extends javascriptobject {  protected twitterresults() {   } //public final string getmaxid() { return "500"; } public final native jsarray<tweet> getresults() /*-{ return this.results; }-*/;  public final native string getmaxid() /*-{ return ''+this.max_id; }-*/; public final native string getrefreshurl() /*-{ return this.refresh_url; }-*/; public final native string getnextpage() /*-{ return this.next_page; }-*/; 

}


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -