0

I have the following structure in my Android project:

map = new Gson().fromJson("[{\n \"ques\": \"20+20=\",\n \"a\": \"40\",\n \"b\": \"60\",\n \"c\": \"80\",\n \"d\": \"220\",\n \"ans\": \"a\"\n },\n\n {\n \"ques\": \"80+80=\",\n \"a\": \"60\",\n \"b\": \"93\",\n \"c\": \"272\",\n \"d\": \"160\",\n \"ans\": \"d\"\n },\n\n {\n \"ques\": \"50+50=\",\n \"a\": \"100\",\n \"b\": \"458\",\n \"c\": \"200\",\n \"d\": \"90\",\n \"ans\": \"a\"\n },\n\n {\n \"ques\": \"25+25=\",\n \"a\": \"78\",\n \"b\": \"45\",\n \"c\": \"50\",\n \"d\": \"43\",\n \"ans\": \"c\"\n },\n\n {\n \"ques\": \"60+90=\",\n \"a\": \"56\",\n \"b\": \"150\",\n \"c\": \"180\",\n \"d\": \"100\",\n \"ans\": \"b\"\n },\n\n {\n \"ques\": \"75+5=\",\n \"a\": \"60\",\n \"b\": \"65\",\n \"c\": \"100\",\n \"d\": \"80\",\n \"ans\": \"d\"\n },\n\n {\n \"ques\": \"60+70=\",\n \"a\": \"150\",\n \"b\": \"130\",\n \"c\": \"609\",\n \"d\": \"517\",\n \"ans\": \"b\"\n },\n\n {\n \"ques\": \"50+10=\",\n \"a\": \"60\",\n \"b\": \"13\",\n \"c\": \"471\",\n \"d\": \"100\",\n \"ans\": \"a\"\n },\n\n {\n \"ques\": \"90+90=\",\n \"a\": \"180\",\n \"b\": \"100\",\n \"c\": \"120\",\n \"d\": \"145\",\n \"ans\": \"a\"\n },\n\n {\n \"ques\": \"40+30=\",\n \"a\": \"60\",\n \"b\": \"50\",\n \"c\": \"70\",\n \"d\": \"80\",\n \"ans\": \"c\"\n }\n]", new TypeToken>>(){}.getType());

But it is very difficult to edit, how do I get GSON to load with the original JSON framework?

2
  • Load the json data from a file or at least use a proper IDE and do something like Alt+Enter > Inject Language Reference > Json Commented Dec 6, 2019 at 13:57
  • How do I load a file through Assets? Commented Dec 6, 2019 at 14:00

1 Answer 1

1

Gson uses its own parser and json types

If you want to use the builtin JSONArray class, then you would pass your string to that rather than Gson, however that wouldn't fix the difficulty of editing the string.

You should instead store it in the assets folder and read it as a file

Android Java; How can I parse a local JSON file from assets folder into a ListView

Sign up to request clarification or add additional context in comments.

Comments