0

Check out this post Reading a json file in Android. What do I replace the below line with-

json_return_by_the_function

I need to save the functions return value in string.

public String loadJSONFromAsset() {
    String json = null;
    try {

        InputStream is = getAssets().open("file_name.json");

        int size = is.available();

        byte[] buffer = new byte[size];

        is.read(buffer);

        is.close();

        json = new String(buffer, "UTF-8");


    } catch (IOException ex) {
        ex.printStackTrace();
        return null;
    }
    return json;

}
JSONObject obj = new JSONObject(json_return_by_the_function);
Community
  • 1
  • 1
user2867267
  • 27
  • 3
  • 8

2 Answers2

0

JSONObject obj = new JSONObject(loadJSONFromAsset());

Smogger
  • 553
  • 5
  • 17
0

The Return value is all ready string

String str1 = loadJSONFromAsset();

Save it where ever u want and then parse

JSONObject obj = new JSONObject(str1 );

  • ok see my this post my textfile here http://stackoverflow.com/questions/19331257/how-to-search-value-from-textfile suppose if i filter file to get only that school which name are "MiddleSchool" how i wil do that???? – user2867267 Oct 12 '13 at 07:58