java - Caused by: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected ':' at line -


i have seen same questions on stackoverflow, tells comma , spaces in json. did nt helped me.

i having json of format pojo

 {"binary":[     {     "attributeindex": 4,     "attributevalue": "no",     "binaryvalue": "1,0"   },   {     "attributeindex": 4,     "attributevalue": "yes",     "binaryvalue": "0,1"   } ]} 

pojo

public class binpojo {      /**      * @param args      */     int attributeindex;     string attributevalue;     string binaryvalue; ,  public class binarypojo {      /**      * @param args      */     jsonarray binary; 

i trying attributeindex,attributevalue,binaryvalue values getting error

caused by: com.google.gson.jsonsyntaxexception: com.google.gson.stream.malformedjsonexception: expected ':' @ line 1 column 65     @ com.google.gson.gson.fromjson(gson.java:818)     @ com.google.gson.gson.fromjson(gson.java:768)     @ com.google.gson.gson.fromjson(gson.java:717)     @ com.google.gson.gson.fromjson(gson.java:689) 

at

binpojo getdata = gson.fromjson(meta.get(j).tostring(), binpojo.class); 

my code:

jsonarray meta = new jsonarray(); //file read string setupdata = bf.readline(); binarypojo d = gson.fromjson(setupdata, binarypojo.class); meta = d.getbinary();   //jsonarray meta holds json data (int j = 0; j < meta.size(); j++) {     binpojo getdata = gson.fromjson(meta.get(j).tostring(), binpojo.class);     system.out.println("gson"+gson.tojson(getdata));     int attrindex = getdata.getattributeindex();     system.out.println("attrindex: "+attrindex);     string attrval = getdata.getattributevalue();                } 

what reason. telling json bad.how can debug this.

edit

once print this:

system.out.println("meta: "+meta.get(j).tostring()); 

my result

meta: {attributeindex=0.0, attributevalue=middleaged, binaryvalue=1,0,0}

and

for (int j = 0; j < meta.size(); j++) {     system.out.println("meta: "+meta.get(j).tostring());     binpojo getdata = null ;     try{         getdata = gson.fromjson(meta.get(j).tostring(), binpojo.class);     }catch(exception e){             e.printstacktrace();     }     system.out.println("gson "+gson.tojson(getdata));     int attrindex = getdata.getattributeindex();     system.out.println("attrindex: "+attrindex);     string attrval = getdata.getattributevalue();                } 

getdata returning null.

gson null java.lang.exception: java.lang.nullpointerexception     @ org.apache.hadoop.mapred.localjobrunner$job.run(localjobrunner.java:354) caused by: java.lang.nullpointerexception 

ah! think that's problem. you're using "json-simple" library (org.json.simple.*) instead of "json java" library (org.json.*). both have classes named jsonarray. org.json.simple.jsonarray json-simple not return json tostring() method org.json.jsonarray "json java" does.

you need use tojsonstring() instead on jsonarray , jsonobject objects.

pay close attention libraries you're using. including them (preferably version numbers) in questions make answering questions easier. class names not unique across projects.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -