title: How to parse or read json file from external storage on Android app
body: <p>I currently implemented parsing json from a server (url). But I couldn't find a way to parse json from sdcard (/Download/example.json). Can someone help me to solve this issue/change this code?</p>
  
  <p>I used asyncTask for this. sample tutorial or sample code is more appreciated. (sorry for my English.)</p>
  
  <pre><code>public class Main extends Activity {
  
          private TextView shopsDisplay;
          private static String searchURL = "http://example.com/sample.json";
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.baby);
              //reference throughout class
              shopsDisplay = (TextView)findViewById(R.id.tweet_txt);
              new GetShops().execute(searchURL);
          }
  private class GetShops extends AsyncTask&lt;String, Void, String&gt; {
              /*
               * Carry out fetching task in background
               * - receives search URL via execute method
               */
              @Override
              protected String doInBackground(String... shopsURL) {
                  //start building result which will be json string
                  StringBuilder shopsFeedBuilder = new StringBuilder();
                  //should only be one URL, receives array
                  for (String searchURL : shopsURL) {
                      HttpClient shopsClient = new DefaultHttpClient();
                      try {
                          //pass search URL string to fetch
                          HttpGet shopsGet = new HttpGet(searchURL);
                          //execute request
                          HttpResponse shopsResponse = shopsClient.execute(shopsGet);
                          //check status, only proceed if ok
                          StatusLine searchStatus = shopsResponse.getStatusLine();
                          if (searchStatus.getStatusCode() == 200) {
                              //get the response
                              HttpEntity shopsEntity = shopsResponse.getEntity();
                              InputStream shopsContent = shopsEntity.getContent();
                              //process the results
                              InputStreamReader shopsInput = new InputStreamReader(shopsContent);
                              BufferedReader shopsReader = new BufferedReader(shopsInput);
                              String lineIn;
                              while ((lineIn = shopsReader.readLine()) != null) {
                                  shopsFeedBuilder.append(lineIn);
                              }
                          }
                          else
                              shopsDisplay.setText("Whoops - something went wrong!");
                      }
                      catch(Exception e){ 
                          shopsDisplay.setText("Whoops - something went wrong!");
                          e.printStackTrace(); 
                      }
                  }
                  //return result string
                  return shopsFeedBuilder.toString();
              }
              /*
               * Process result of search query
               * - this receives JSON string representing shops with search term included
               */
              protected void onPostExecute(String result) {
                  //start preparing result string for display
                  StringBuilder shopsResultBuilder = new StringBuilder();
                  try {
                      //get JSONObject from result
                      JSONObject resultObject = new JSONObject(result);
                      //get JSONArray contained within the JSONObject retrieved - "results"
                      JSONArray shopsArray = resultObject.getJSONArray("shops");
                      //loop through each item in the shops array
                      for (int t=0; t&lt;shopsArray.length(); t++) {
                          //each item is a JSONObject
                          JSONObject shopsObject = shopsArray.getJSONObject(t);
                          //for if condition
                          String id = (String) shopsObject.get("id");
                          //get the name and description for each shops
                          if (id.equals("550")){
                          shopsResultBuilder.append(shopsObject.getString("name")+": ");
                          shopsResultBuilder.append(shopsObject.get("description")+"\n\n");
                          }
                      }
                  }
                  catch (Exception e) {
                      shopsDisplay.setText("Whoops - something went wrong!");
                      e.printStackTrace();
                  }
                  //check result exists
                  if(shopsResultBuilder.length()&gt;0)
                      shopsDisplay.setText(shopsResultBuilder.toString());
                  else
                      shopsDisplay.setText("Sorry - no shops found for your search!");
              }
          }
  
  
  }
  </code></pre>