Java Parsing JSON with GSON -


i new java , json , i'm trying parse following json using gson. however, having problem in don't have errors object empty.

{     "pac": [         {             "customername": "test"         }     ] } 

this class im trying make object of:

public class customer{  /** customer name. */ private string customername;  /**  * gets customer name.  *  * @return customer name  */ public string getcustomername() {     return customername; }  /**  * sets customer name.  *  * @param customername new customer name  */ public void setcustomername(string customername) {     this.customername = customername; } 

i'm using try , parse:

gson gson = new gson(); customer = gson.fromjson(jsonfile, customer.class); 

i appriciate if guys had tips.

your json show there object have property pac.

this property pac array of customer

so try :

public class customers {      public list<customer> pac; // list java.util  } 

and then

customers = gson.fromjson(jsonfile, customers.class); 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -