To McDonald's, KFC coupon interface data as an example of data analysis method, easy to understand

Source: Internet
Author: User

To McDonald's, KFC coupons interface data for an example of data analysis method, simple and understandable, this is my personal feel is a relatively simple and understandable JSON data parsing method:


Look at the code for one of the classes

Package Com.example.text_json_deno_model;import Java.util.arraylist;import Java.util.list;import Org.json.jsonarray;import Org.json.jsonexception;import Org.json.jsonobject;public class Coupons {private List< kfc> coupons;p rivate string end;private int id;private string label;private string start;public list<kfc> GetC Oupons () {return coupons;} public void setcoupons (list<kfc> coupons) {this.coupons = coupons;} Public String Getend () {return end;} public void SetEnd (String end) {this.end = end;} public int getId () {return ID;} public void setId (int id) {this.id = ID;} Public String Getlabel () {return label;} public void SetLabel (String label) {this.label = label;} Public String Getstart () {return start;} public void Setstart (String start) {This.start = start;} Public coupons (Jsonobject jsonobject) throws Jsonexception{constructjson (Jsonobject);} private void Constructjson (Jsonobject jsonobject) throws Jsonexception {if (!jsonobject.isnull ("End")) {End =jsonobject . getString ("End"); if (!jsonobject.isnull ("id")) {ID =jsonobject.getint ("id");} if (!jsonobject.isnull ("label")) {label =jsonobject.getstring ("label");} if (!jsonobject.isnull ("start")) {start =jsonobject.getstring ("Start");} if (!jsonobject.isnull ("coupons")) {list<kfc> KFCs =new arraylist<kfc> (); Jsonarray object =jsonobject.getjsonarray ("Coupons"), if (object instanceof Jsonarray) {for (int i = 0; i < Object.le Ngth (); i++) {KFC KFC =new KFC (Object.getjsonobject (i)); Kfcs.add (KFC);} Coupons =kfcs;}}}
It is easy to parse the data yourself into an object. I sent a demo I wrote up,: http://download.csdn.net/detail/u012808234/8385311

To McDonald's, KFC coupon interface data as an example of data analysis method, easy to understand

Related Article

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.