Nevaeh
Nevaeh

Reputation: 1569

How to use bundled json in my android application?

I need to use bundled json in my application.So i added my json file under assets folder.How to write code for using this ?Please help...

Upvotes: 0

Views: 41

Answers (1)

Waqar Ahmed
Waqar Ahmed

Reputation: 5068

you first need to read your json from asset folder

    InputStream is = appContext.getAssets().open("myJson.json");
int size = is.available();
buffer = new byte[size];
is.read(buffer);
is.close();
String bufferString = new String(buffer);

and then you can do

JSONObject obj = new JSONObject(bufferString);

and now obj contain your json.

Upvotes: 2

Related Questions