json - In Android how can I post this JSONObject to a server? -


hashmap<string,string> list = new hashmap(); list.put("uid",string.valueof(3)); list.put("longitude", "10.13"); list.put("latitude", "20.33");  jsonobject jo = new jsonobject(list); 

the documentation not entirely clear next. given server url http://example.com/update.php , server able parse json object.

i unable use deprecated apache httpclient object post because i'm using api 23 , downgrading api not option

there multiple http client libraries available google volley,retrofit , loopj async . prefer volley when working json format.

for posting json object via volley this:

jsonobjectrequest strreq = new jsonobjectrequest(request.method.post,         your_url, yourjsonobject, new response.listener<jsonobject>() {      @override     public void onresponse(jsonobject jobj) {         // these if request successful     } }, new response.errorlistener() {      @override     public void onerrorresponse(volleyerror error) {         // these if request has errors     } }); 

these useful links tutorial on google volley:

android working volley library

an introduction volley


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

html - Outlook 2010 Anchor (url/address/link) -

android - How to create dynamically Fragment pager adapter -