Several APIs for JSON are already included in the Android JDK development package:
You can also download the JSON package: Http://files.cnblogs.com/java-pan/lib.rar
Jsonobject Online api:http://json-lib.sourceforge.net/apidocs/jdk15/index.html
To enable the program to run, the Json-lib package must be introduced, and the Json-lib package relies on the following jar packages:
Commons-lang.jar
Commons-beanutils.jar
Commons-collections.jar
Commons-logging.jar
Ezmorph.jar
Json-lib-2.2.2-jdk15.jar
1,jsonobject in the form of a map is the same as the key-value pairs, but jsonobject with the colon ":", map with a comma
JSON object, which is a key corresponding to a value, using curly braces {}, such as: {Key:value}
Example:JSON object
{
"publisher": "People's post and telecommunications press",
"Image": "Http://img3.doubanio.com\/mpic\/s27308766.jpg",
"Isbn10": "7115314640",
"Isbn13": "9787115314642",
"title": "Android Development Introduction and Combat",
"url": "http:\/\/api.douban.com\/v2\/book\/24701842",
"Price": "59.00 Yuan"
}
The Jsonobject class is a final class that inherits the object and implements the JSON interface
The construction method is as follows:
Jsonobject (); Create an empty Jsonobject object
Jsonobject (Boolean isNull); Create an empty Jsonobject object
The general method is as follows:
Frombean (object bean); Static method that creates a Jsonobject object from a Pojo object
Fromjsonobject (Jsonobject object); A static method that constructs a Jsonobject object from another Jsonobject object
Fromjsonstring (jsonstring string); static method, creating a Jsonobject object from a jsonstring
ToString (); Convert the Jsonobject object to a JSON-formatted string
Iterator (); Returns a iterator object to traverse the element
2, Jsonarray, JSON array, using brackets [], except that the items inside the array are also JSON key-value pairs.
Example:["string1", "string2"].,[jsonobject1,jsonobject2,........]
Jsonarray is a final class, inherits the object, implements the JSON interface
The construction method is as follows:
Jsonarray (); Constructs an empty Jsonarray object
The general method is as follows:
FromArray (object[] array); static method, creating a Jsonarray object from a Java array
Fromcollection (Collection Collection); static method, creating a Jsonarray object from the Collection collection object
FromString (string string), static method, constructs a Jsonarray object from a JSON-formatted string
ToString (); Convert the Jsonarray object to a JSON-formatted string
Iterator (); Returns a iterator object to traverse the element
A simple example of each column of XML and JSON strings:
json:{"password": "123456", "username": "Zhang San"}xml://parsing XML Technology: dom,sax,pull Technology <?xml version= "1.0" encoding= "UTF-8"? > <user_info><password>123456</password><username> Zhang San </username></user_info >
The use of Jsonobject and Jsonarray in Android