The JSON string here is an example of the JSON Format String above the public time line.
Http://api.fanfou.com/statuses/public_timeline.json
Currently, HTTP basic verification is still used. If you are not clear about how to log on and obtain data through the APIS, refer to my
Http://blog.csdn.net/w59879213/archive/2011/01/14/6140523.aspx
This article describes how to perform HTTP basic verification and obtain the returned data using APIs that are not supported.
The premise of the project here is that the data has been obtained and the data string is JSON
The android development environment includes the org. JSON package,
However, if you create a Java project, org. JSON package. you can search for JSON. JAR file, right-click your JRE system library-> build path and add it to your project.
Add
Import org. JSON. jsonarray; <br/> Import org. JSON. jsonexception; <br/> Import org. JSON. jsonobject;
The parsing steps are actually very simple.
First, get the array of all data through the jsonarray object,
Jsonarray array = new jsonarray (JSON );
The example of "meal no" is the information of all speeches, but the information of each statement of "meal no" is nested with a JSON string of user information.
Therefore, when obtaining the information of each statement, you need to obtain the JSON string marked with user again.
Jsonobject object = array. getjsonobject (I); <br/> // obtain the nested JSON string <br/> string users = object. getstring ("user"); <br/> // explain the nested JSON string to obtain the usable object. <br/> jsonobject user = new jsonobject (users );
After parsing, you can use the getstring ("key") method of the object to obtain the corresponding value ~
The Code is as follows:
// Obtain all JSON strings. <br/> jsonarray array = new jsonarray (JSON); <br/> for (INT I = 0; I <array. length (); I ++) <br/>{< br/>/* obtain the list of the first record from the list, including the information ID, sender... <br/> The list contains another JSON string */<br/> jsonobject object = array. getjsonobject (I); <br/> // obtain the nested JSON string <br/> string users = object. getstring ("user"); <br/> // explain the nested JSON string to obtain the usable object. <br/> jsonobject user = new jsonobject (users); <br/> system. out. println (object. getstring ("ID") + ":" + User. getstring ("Birthday"); <br/>}