Android parses JSON

Source: Internet
Author: User

public void parseSearchDirectAllData(ArrayList
 
   programmeSites) {if(programmeSites != null) {programmeSites.clear();try {             JSONArray segsArray = new JSONArray(jsonString);                    if (segsArray != null)for (int k = 0; k < segsArray.length(); k++) {JSONObject segObject = segsArray.optJSONObject(k);if (segObject != null) {if(segObject.has("programmeSite")) {JSONArray jsonResultsArray = segObject.optJSONArray("programmeSite");if(jsonResultsArray != null && jsonResultsArray.length() > 0) {for (int i = 0; i < jsonResultsArray.length(); i++) {JSONObject jsonResultObject = jsonResultsArray.optJSONObject(i);if(jsonResultObject != null) {ProgrammeSite programmeSite = new ProgrammeSite();programmeSite.setSiteId(jsonResultObject.optInt("siteId"));if(jsonResultObject.has("episode")) {JSONArray jsonResultsSerisesArray = jsonResultObject.optJSONArray("episode");if(jsonResultsSerisesArray != null && jsonResultsSerisesArray.length() > 0) {ArrayList
  
    episodes = new ArrayList
   
    ();for (int j = 0; j < jsonResultsSerisesArray.length(); j++) {JSONObject jsonResultSerisesObject = jsonResultsSerisesArray.optJSONObject(j);if(jsonResultSerisesObject != null) {Episode episode = new Episode();episode.setName(jsonResultSerisesObject.optString("name"));episode.setUrl(jsonResultSerisesObject.optString("url"));episodes.add(episode);}}programmeSite.setEpisodes(episodes);}}programmeSites.add(programmeSite);}}}}}}} catch (Exception e) {Logger.e(Youku.TAG_GLOBAL, "ParseJson#parseSearchDirectAllData()", e);}}}
   
  
 


The JSON data entered in the above Code is as follows:

["ProgrammeSite": [{// begin "id": 405642, "siteId": 17, "episode": [{"url": "http://www.letv.com/ptv/vplay/1606059.html", "name ": "Black Fox 01", "seconds": 2701, "orderId": 1, "orderStage": 1, "lastUpdate": 1376496000, "viewOrder": 1, "logo ": "", "tagType": 0, "vid": 0, },{ "url": "http://www.letv.com/ptv/vplay/1427315.html", "name": "black fox 02", "seconds ": 2699, "orderId": 2, "orderStage": 2, "lastUpdate": 1376496000, "viewOrder": 1, "logo": "", "tagType": 0, "vid": 0,},]} // end {// begin "id": 405715, "siteId": 1, "episode": [{"url ": "http://www.tudou.com/albumplay/hLzWIWJyMXk/AHf67i8rVrg.html", "name": "black fox-1st set", "seconds": 2699, "orderId": 1, "orderStage": 1, "lastUpdate": 1386604800, "viewOrder": 2, "logo": "http://r3.ykimg.com/0543040850EB192B6A0A470A11CD1DA6", "tagType": 0, "vid": 130472276, },{ "url": "http://www.tudou.com/albumplay/hLzWIWJyMXk/XaJL16jobbE.html ", "name": "-2nd", "seconds": 2699, "orderId": 2, "orderStage": 2, "lastUpdate": 1387468800, "viewOrder ": 2, "logo": "http://r3.ykimg.com/0543040850BE87EF6A0A442EFAD0048F", "tagType": 0, "vid": 130472277,},]} // end]



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.