Android: parse the JSON file in the raw folder with gson? -


i trying parse json file"ssid-number" in raw folder gson. parse_ssid method parses json file , finds mapping passed ssid string. getting @ momenat error:the method getwifilist() undefined type wifijson @ line list<wifijson> wifijson = obj.getwifilist();. approach correct?

json file:

{     "data": [         {             "ssid": "kd privat",             "route_number": 1         },         {             "ssid": "kd wlan hotspot",             "route_number": 4         },         {             "ssid": "fr wlan",             "route_number": 6         }     ] } 

parse_ssid method in mainactivity:

        private int parse_ssid(string ssid) {               inputstream raw =  getresources().openrawresource(r.raw.ssid_number);              reader rd = new bufferedreader(new inputstreamreader(raw));              gson gson = new gson();                         wifijson obj = gson.fromjson(rd, wifijson.class);             // iterate through list             list<wifijson> wifijson = obj.getwifilist(); //here error.             iterator iterator = wifijson.iterator();             while (iterator.hasnext()) {                 wifijson wifielement = (wifijson) iterator.next();                 system.out.println(wifielement.getssid() + "----"                         + wifielement.getroute_number());             }          } 

wifijson class:

public class wifijson {     private string ssid;     private int route_number;      public wifijson(string ssid, int route_number) {         this.ssid = ssid;         this.route_number = route_number;      }      private string getssid() {         return ssid;     }      private void setssid(string ssid) {         this.ssid = ssid;     }      private int getroute_number() {         return route_number;     }      private void setroute_number(int route_number) {         this.route_number = route_number;     }      @override     public string tostring() {         return "wifijson [ssid=" + ssid + ", route_number=" + route_number                 + "]";     }    } 

wifijsonlist class:

import java.util.arraylist;  public class wifijsonlist {     private arraylist<wifijson> data;      public arraylist<wifijson> getwifilist() {         return data;     }     public void setwifilist(arraylist<wifijson> wifilist) {         this.data = wifilist;     } } 

this:

wifijson obj = gson.fromjson(rd, wifijson.class);  

should

wifijsonlist obj = gson.fromjson(rd, wifijsonlist.class); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -