A
A
Anton2016-03-28 20:38:22
Java
Anton, 2016-03-28 20:38:22

How to get a local json file and output a list?

There is a JSON file with a bunch of objects and arrays. It is necessary to parse it and subsequently display the values ​​of the necessary keys in the list.
This option raises no questions. Everything is clear here:

public class MainActivity extends ListActivity {

    private ArrayAdapter<String> myAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final String[] simpleArray = new String[] { "Первый", "Второй", "Третий" };

        myAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, simpleArray);
        
        setListAdapter(myAdapter);
    }
}

But how to connect the JSON file here, which is in the assets folder?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2016-03-28
@hummingbird

You need to use AssetManager . You can get an instance of it with Context.getAssets(). Parse the file with either standard JsonObject/JsonArray or something like Gson.

E
Elysey, 2016-03-28
@Elysey

Here it is described: stackoverflow.com/questions/19945411/android-java-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question