try
{
// Load File
BufferedReader jsonReader = new BufferedReader(new InputStreamReader(getActivity().getResources().openRawResource(R.raw.province)));
StringBuilder jsonBuilder = new StringBuilder();
for (String line = null; (line = jsonReader.readLine()) != null;)
{
jsonBuilder.append(line).append("
");
}
// ParsJson
JSONTokener tokener = new JSONTokener(jsonBuilder.toString());
JSONArray jsonArray = new JSONArray(tokener);
List<ProvinceList> fields = new ArrayList<>();
for(int i = 0; i < jsonArray.length(); i++)
{
JSONObject object = jsonArray.getJSONObject(i);
fields.add(new ProvinceList(object.getString("id"), object.getString("name")));
}
setDialogProvince(fields);
}
catch (FileNotFoundException e)
{
}
catch (IOException e) {
Log.e("JSON_ERROR", "ioError");
}
catch (JSONException e) {
e.printStackTrace();
}