Use JSON to implement HTTP requests in Android, plus several examples!

Source: Internet
Author: User

I have to say that the JSON format is indeed very good, fast and simplified a lot of operations.
In Android, the android SDK has encapsulated the entire JSON-related operation for us, which is very convenient to use.

The following is the implementation process of a standard JSON request:

Httppost request = new httppost (URL); <br/> // encapsulate a JSON object <br/> jsonobject Param = new jsonobject (); <br/> param. put ("name", "rarnu"); <br/> param. put ("password", "123456"); <br/> // bind to the request entry <br/> stringentity Se = new stringentity (Param. tostring (); <br/> request. setentity (SE); <br/> // send the request <br/> httpresponse = new defaulthttpclient(.exe cute (request); <br/> // the string to be replied, this is also the data stored in JSON format <br/> string retsrc = entityutils. tostring (httpresponse. getentity (); <br/> // generate a JSON object <br/> jsonobject result = new jsonobject (retsrc); <br/> string token = result. get ("token "); 

 

Support JSON remote access under Android (recommended this blog): http://marshal.easymorse.com/archives/1707

About Android JSON writing class -- jsonwriter, easy to generate data in JSON format: http://disanji.net/2011/03/05/android-3-0-json-jsonwriter/

Android JSON parsing sample code, daily wiki Widget: http://www.android123.com.cn/androidkaifa/664.html

The client sends data to the server, one is in the URL with parameters, one is the JSON data transmission method (small stranger): http://henzil.easymorse.com /? P = 241

Android access PHP retrieve JSON data: http://blog.lrenwang.com/post/114/

How to send a request with an android JSON object:

Http://cn.webdiscussion.info/question/3027066/if he sends a request with android-jsonobject

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.