Skip to content

Instantly share code, notes, and snippets.

@codenameone
Created February 10, 2016 07:08
Show Gist options
  • Save codenameone/22efe9e04e2b8986dfc3 to your computer and use it in GitHub Desktop.
Save codenameone/22efe9e04e2b8986dfc3 to your computer and use it in GitHub Desktop.
This is a simple block of code used by some samples in Codename One it fetches housing listings
int pageNumber = 1;
java.util.List<Map<String, Object>> fetchPropertyData(String text) {
try {
ConnectionRequest r = new ConnectionRequest();
r.setPost(false);
r.setUrl("http://api.nestoria.co.uk/api");
r.addArgument("pretty", "0");
r.addArgument("action", "search_listings");
r.addArgument("encoding", "json");
r.addArgument("listing_type", "buy");
r.addArgument("page", "" + pageNumber);
pageNumber++;
r.addArgument("country", "uk");
r.addArgument("place_name", text);
NetworkManager.getInstance().addToQueueAndWait(r);
Map<String,Object> result = new JSONParser().parseJSON(new InputStreamReader(new ByteArrayInputStream(r.getResponseData()), "UTF-8"));
Map<String, Object> response = (Map<String, Object>)result.get("response");
return (java.util.List<Map<String, Object>>)response.get("listings");
} catch(Exception err) {
Log.e(err);
return null;
}
}
@codenameone
Copy link
Author

Simple webservice call that also serves as a sample usage for usage code for JSONParser, NetworkManager & ConnectionRequest.

This function is used externally by other gists such as the one for InfiniteScrollAdapter.

This sample code is from the Codename One project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment