JSON Parsing


 

  1. Simple JSON Data
  2. JSON Parsing to ListView
  3. JSON Parsing to Spinner
  4. Complex JSON Data
  5. Parsing Secured JSON Data
  6. Writing a JSON file using JsonWriter

 

1. Simple JSON Example
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new Class, MyHttpURLConnection.java and add following code :

Step 5 : Create simple_json.php file, copy paste this code and upload it to the server:

Step 6 : Open AndroidManifest.xml and add following code :

ScreenShot:

json_txt

Download_button

 

2. JSON Parsing to ListView
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyHttpURLConnection.java and add following code :

Step 5 : Create list_multipletext_json.php file, copy paste this code and upload it to the server :

Step 6 : Open AndroidManifest.xml and add following code :

ScreenShot:

json_list json_list2

Download_button

 

3. JSON Parsing to Spinner
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package ->Create new class, MyHttpURLConnection.java and add following code :

Step 5 : Create simplelist_json.php file, copy paste this code and upload it to the server :

Step 6 : Open AndroidManifest.xml and add following code :

ScreenShot:

json_spin3 json_spin2 json_spin

Download_button

 

4. Complex JSON Data
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyHttpURLConnection.java and add following code :

Step 5 :Create complex_json.php file, copy paste this code and upload it to the server :

Step 6 : Open AndroidManifest.xml and add following code :

ScreenShot:

json_complex2 json_complex

Download SourceCode

 

5. Parsing Secured JSON Data
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyHttpURLConnection.java and add following code :

Step 5 :Create list_multipletext_json.php file, copy paste this code and upload it to the server with Basic Authentication (like using .htaccess as):

Step 6 :Open AndroidManifest.xml and add following code :

ScreenShot:

json_secured3 json_secured2 json_secured

Download SourceCode

 

6. Writing a JSON file using JsonWriter
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, AndroidVersionHelper.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:

jsonwriter jsonwriter2 jsonwriter3

Download SourceCode