How to parse local JSON file in assets?

后端 未结 4 1601
灰色年华
灰色年华 2021-02-14 20:25

I have a JSON file in my assets folder. That file has one object with an array. The array has 150+ objects with each having three strings.

For each of these 150+ objects

4条回答
  •  迷失自我
    2021-02-14 20:47

    Put your json file in raw folder and whit Gson library you can pars json :

    Reader reader= new InputStreamReader(getResources().openRawResource(R.raw.json_test));
    JsonElement json=new Gson().fromJson(reader,JsonElement.class); 
    

    You can use this JsonElemnt for Gson or if you want json as string you can do this :

    String jsonString=json.toString();
    

提交回复
热议问题