Use JSON to implement HTTP requests under Android, plus a few examples!

Source: Internet
Author: User

It has to be said that the JSON format is really wonderful, fast and simplifies a lot of operations
Under Android, the Android SDK has encapsulated the entire JSON-related operation for us and is very easy to use

The following is the implementation of a standard JSON request:

[Java]View Plaincopyprint?
  1. HttpPost request = new HttpPost (URL);
  2. Encapsulates a JSON object first
  3. Jsonobject param = new Jsonobject ();
  4. Param.put ("name", "Rarnu");
  5. Param.put ("password", "123456");
  6. Bind to request Entry
  7. Stringentity se = new stringentity (param.tostring ());
  8. Request.setentity (SE);
  9. Send Request
  10. HttpResponse HttpResponse = new Defaulthttpclient (). Execute (Request);
  11. Gets the answer string, which is also a JSON format for saving data
  12. String retsrc = entityutils.tostring (Httpresponse.getentity ());
  13. Generating a JSON object
  14. Jsonobject result = new Jsonobject (RETSRC);
  15. String token = result.get ("token");

Remote access with JSON supported under Android (recommended this blog): http://marshal.easymorse.com/archives/1707

About the Android JSON write class--jsonwriter, easily generate JSON-formatted data: 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 with parameters in the URL, and one for the JSON data sending method (MOMO): http://henzil.easymorse.com/?p=241

Android accesses PHP to 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/How to send a request to the Android-json object

Use JSON to implement HTTP requests under Android, plus a few examples!

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.