java - GSON - JsonSyntaxException - Expected name at line 7 column 4 -


i have following result class object returned json.

public class result {     public string objectid;     public string dtype;     public string type;     public string name;     public string description;      public result() {         this.objectid = "";         this.dtype= "";         this.type="";         this.name= "";         this.description = "";     }      public string getobjectid() {         return objectid;     }      public void setobjectid(string s) {         this.objectid = s;     }      public string getdtype() {         return dtype;     }      public void setdtype(string s) {         this.dtype= s;     }      public string gettype() {         return type;     }      public void settype(string s) {         this.type = s;     }      public string getname() {         return name;     }      public void setname(string s) {         this.name = s;     }      public string getdescription() {         return description;     }      public void setdescription(string s) {         this.description = s;     }  } 

i have configuration json read main .java , returned json http response. below:

{         "objectid" : "test",         "dtype" : "test",         "type" : "test",         "name" : "test",         "description" : "test" // removed }, {         "objectid" : "test",         "dtype" : "test",         "type" : "test",         "name" : "test",         "description" : "test" } 

main .java

using gson, reads configuration.json file , has return json.

my code:

gson g = new gson(); result r = g.fromjson(res.tostring(), result.class); 

where res.tostring() gets me configuration.json file content string.

my problem:

i experiencing following exception:

exception com.google.gson.jsonsyntaxexception: com.google.gson.stream.malformedjsonexception: use jsonreader.setlenient(true) accept malformed json @ line 7 column 3
com.google.gson.jsonsyntaxexception: com.google.gson.stream.malformedjsonexception: use jsonreader.setlenient(true) accept malformed json @ line 7 column 3

any pointers?

if actual json: have comma here , spelling error. error says have bad json syntax. 1 of first places look.

{             "objectid" : "test",             "dtype" : "test",             "type" : "test",             "name " : "test",             "description" : "test", //delete comma             },             {             "objectid" : "test",             "dtyoe" : "test",  // spelling error             "type" : "test",             "name " : "test",             "description" : "test"     } 

you seem parsing 2 objects , telling gson want 1 result object it. consider either parsing objects separately or tell gson want result array back


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

java - More than one row with the given identifier was found: 1, for class: com.model.Diagnosis -