i'm trying parse json object using gson this:
1st,2nd,3rd,4th
gson gson=new gson(); map<string, hashset<string>> map = new hashmap<string, hashset<string>>(); map = (map<string, hashset<string>>) gson.fromjson(jsontxt, map.getclass());
this json looks like:
"{ \"rao\":[\"q7293658\",\"\",\"q7293657\",\"q12953055\",\"q3531237\",\"q4178159\",\"q1138810\",\"q579515\",\"q3365064\",\"q7293664\",\"q1133815\"], \"hani durzy\":[\"\"], \"louise\":[\"\",\"q1660645\",\"q130413\",\"q3215140\",\"q152779\",\"q233203\",\"q7871343\",\"q232402\",\"q82547\",\"q286488\",\"q156723\",\"q3263649\",\"q456386\",\"q233192\",\"q14714149\",\"q12125864\",\"q57669\",\"q168667\",\"q141410\",\"q166028\"], \"reyna\":[\"q7573462\",\"q2892895\",\"q363257\",\"q151944\",\"q3740321\",\"q2857439\",\"q1453358\",\"q7319529\",\"q733716\",\"q16151941\",\"q7159448\",\"q5484172\",\"q6074271\",\"q1753185\",\"q7319532\",\"q5171205\",\"q3183869\",\"q1818527\",\"q251862\",\"q3840414\",\"q5271282\",\"q5606181\"] }"
i keep getting error:
expected begin_object string @ line 1 column 2
i don't think has fact begins "
, suggest in this question, since when removed first , last quotes got error expected name @ line 2 column 3
my full code here on github page, it's pretty short.
i'm trying reverse this procedure. this related question.
update
file f = new file("/home/matthias/workbench/sutd/nytimes_corpus/wdtk-parent/wdtk-examples/json_output/user.json"); string jsontxt = null; if (f.exists()) { inputstream = new fileinputstream("/home/matthias/workbench/sutd/nytimes_corpus/wdtk-parent/wdtk-examples/json_output/user.json"); jsontxt = ioutils.tostring(is); } gson json = new gson(); map<string, hashset<string>> map = new hashmap<string, hashset<string>>(); map = (map<string, hashset<string>>) json.fromjson(jsontxt, map.getclass()); system.out.println(map);
you've escaped "
characters , wrapped whole json in quotes if string
constant in code (perhaps there @ 1 point). jsonmapfileexample
reading json file on disk - there's no reason escape quotes in dedicated json file.
try removing outer "
characters and \
escapes around each key , value. can paste json directly number of online json validators double-check. contents of file should valid json; you've pasted not.