Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Load local JSON

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();
        }
Comment

PREVIOUS NEXT
Code Example
Java :: Example: My favorite cities 
Java :: java trim unicode u200b 
Java :: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode -[IDENT] IdentNode: 
Java :: using new to create arrays 
Java :: andriod button wont change color 
Java :: confirmation dialog android 
Java :: hide frame ( acces to the top level component ) 
Java :: could not find or load main class org.apache.catalina.startup.bootstrap caused by: java.lang.classnotfoundexception: org.apache.catalina.startup.bootstrap 
Java :: Draw an item using System.out.println 
Java :: why use var in java 
Java :: serilize filke in java 
Java :: how to print a sentence out in a string of camel case java 
Java :: float division by zero 
Java :: java non blocking notifier 
Java :: how to find the size of table in java 
Java :: findbyname in jpa 
Java :: java code file 
Java :: thread Exemple 
Java :: system program j 
Java :: java enum name() 
Java :: javafx treeview directory 
Java :: aaa testing java 
Java :: java default constructor 
Java :: java optional parameters 
Java :: java lambda function 
Java :: adding an element to the end of a linked list java 
Java :: Java Filters 
Java :: number of matches regex java 
Java :: java swing tablecellrenderer 
Java :: java 8 list to map with occurrences 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =