Created
June 18, 2013 08:28
-
-
Save ochilab/5803605 to your computer and use it in GitHub Desktop.
GWTでJSONPを利用するサンプル。Twitterを例にしていますが、今は無効です。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String url = "https://api.twitter.com/1/trends/23424856.json"; //このURLは現在無効です | |
JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); | |
jsonp.requestObject(url, new AsyncCallback<JsArray<Feed>>() { | |
@Override | |
public void onFailure(Throwable caught) { | |
// TODO エラー処理 | |
} | |
@Override | |
public void onSuccess(JsArray<Feed> result) { | |
System.out.println("SUCCESS:"+result.length()); | |
JsArray<User> users = result.get(0).getTrends(); | |
for(int i=0; i<users.length(); i++) { | |
System.out.println(i+": "+users.get(i).getName()); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.ochilab.jsonp.client; | |
import com.google.gwt.core.client.JavaScriptObject; | |
import com.google.gwt.core.client.JsArray; | |
class Feed extends JavaScriptObject { | |
protected Feed() {} | |
public final native JsArray<User> getTrends() /*-{ | |
return this.trends; | |
}-*/; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment