Created
February 10, 2016 07:08
-
-
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
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
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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