-1

I have a online json file with arrays with categories as follows:

[{"id":1,"name":"Moda","howmuch":42}, (...)]

And there's 11 of these categories. Now what I need is to make that the app will download these arrays and put them to the Android app, so user can choose a category. It cannot be hardcoded to strings.xml.

2 Answers2

0

I think you're searching for this, On app start you save your this arrays into shared Preferences or you can save to your Sqlite database

Dipesh
  • 36
  • 3
0

You can do like this :

String result = "your result here";
        try {
            JSONArray data = new JSONArray(result);
            if(data.length() > 0){
               for (int i =0; i < data.length(); i++){
                   String id = data.getJSONObject(i).getString("id");
                   String name = data.getJSONObject(i).getString("name");
                   String howmuch = data.getJSONObject(i).getString("howmuch");
               }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
Manoj Srivastava
  • 670
  • 5
  • 16