├── .gitignore ├── .idea ├── encodings.xml ├── gradle.xml ├── misc.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── herndon │ │ └── webservicedataparse │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── herndon │ │ │ └── webservicedataparse │ │ │ ├── MainActivity.java │ │ │ ├── RestClient.java │ │ │ ├── StudentService.java │ │ │ └── model │ │ │ ├── Favorites.java │ │ │ ├── Skills.java │ │ │ ├── Student.java │ │ │ └── Tests.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── herndon │ └── webservicedataparse │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.herndon.webservicedataparse" 7 | minSdkVersion 19 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | sourceSets { 20 | main { 21 | java.srcDirs = ['src/main/java', 'src/main/java/instinctcoder.jsonparseretrofit/model'] 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: 'libs', include: ['*.jar']) 28 | implementation 'com.android.support:appcompat-v7:28.0.0' 29 | implementation 'com.squareup.retrofit:retrofit:1.9.0' 30 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 34 | } 35 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/herndon/webservicedataparse/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.herndon.webservicedataparse; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.herndon.webservicedataparse", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/herndon/webservicedataparse/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.herndon.webservicedataparse; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.Menu; 6 | import android.view.MenuItem; 7 | import android.view.View; 8 | import android.widget.ArrayAdapter; 9 | import android.widget.Button; 10 | import android.widget.Spinner; 11 | import android.widget.TextView; 12 | import android.widget.Toast; 13 | 14 | import com.herndon.webservicedataparse.model.Student; 15 | 16 | import java.util.List; 17 | 18 | 19 | import retrofit.Callback; 20 | import retrofit.RetrofitError; 21 | import retrofit.client.Response; 22 | 23 | public class MainActivity extends AppCompatActivity { 24 | RestClient restClient; 25 | Button btnParse; 26 | TextView tvResult; 27 | Spinner spinnerJson; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_main); 33 | restClient = new RestClient(); 34 | 35 | btnParse= (Button) findViewById(R.id.btnParse); 36 | tvResult = (TextView) findViewById(R.id.txtResult); 37 | 38 | // Array of choices 39 | String jsonExample[] = {"Array","Array with Objects","Object","Object with Nested Array","Object with Nested Object", "Object with Nested Arrays and Objects"}; 40 | 41 | spinnerJson = (Spinner) findViewById(R.id.spinnerJSON); 42 | 43 | ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, jsonExample); 44 | spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view 45 | spinnerJson.setAdapter(spinnerArrayAdapter); 46 | 47 | 48 | btnParse.setOnClickListener(new View.OnClickListener() { 49 | public void onClick(View v) { 50 | // Perform action on click 51 | //Call to server to JSON File. this is a async calling 52 | switch (spinnerJson.getSelectedItem().toString()) { 53 | case "Array": 54 | restClient.getService().getArray(new Callback>() { 55 | @Override 56 | public void success(List items, Response response) { 57 | String result = ""; 58 | for (int i = 0; i < items.size(); i++) { 59 | result += "Array :[" + i + ']' + items.get(i) + 'n'; 60 | } 61 | tvResult.setText(result); 62 | } 63 | 64 | @Override 65 | public void failure(RetrofitError error) { 66 | Toast.makeText(MainActivity.this, error.getMessage().toString(), Toast.LENGTH_LONG).show(); 67 | } 68 | }); 69 | break; 70 | case "Array with Objects": 71 | restClient.getService().getArrayWithObjects(new Callback>() { 72 | @Override 73 | public void success(List students, Response response) { 74 | String result = ""; 75 | for (int i = 0; i < students.size(); i++) { 76 | result += "Name:" + students.get(i).name + 'n' 77 | + "Age:" + students.get(i).age + "nn"; 78 | } 79 | tvResult.setText(result); 80 | } 81 | 82 | @Override 83 | public void failure(RetrofitError error) { 84 | Toast.makeText(MainActivity.this, error.getMessage().toString(), Toast.LENGTH_LONG).show(); 85 | } 86 | }); 87 | break; 88 | case "Object": 89 | restClient.getService().getObject(new Callback() { 90 | @Override 91 | public void success(Student student, Response response) { 92 | tvResult.setText("First name: " + student.first + 'n' + 93 | "Last name: " + student.last + 'n' + 94 | "Age; " + student.age + 'n' + 95 | "Sex; " + student.sex + 'n' + 96 | "Registered; " + student.registered); 97 | } 98 | 99 | @Override 100 | public void failure(RetrofitError error) { 101 | Toast.makeText(MainActivity.this, error.getMessage().toString(), Toast.LENGTH_LONG).show(); 102 | } 103 | }); 104 | break; 105 | 106 | case "Object with Nested Array": 107 | restClient.getService().getObjectWithNestedArray(new Callback() { 108 | @Override 109 | public void success(Student student, Response response) { 110 | String result = ""; 111 | result = "First name: " + student.first + 'n' + 112 | "Last name: " + student.last + 'n' + 113 | "Age: " + student.age + 'n' + 114 | "Sex: " + student.sex + 'n' + 115 | "Registered: " + student.registered + 'n'; 116 | 117 | if (student.interests.size() > 0) { 118 | for (int i = 0; i < student.interests.size(); i++) { 119 | result += "Array :[" + i + ']' + student.interests.get(i) + 'n'; 120 | } 121 | 122 | } 123 | tvResult.setText(result); 124 | } 125 | 126 | @Override 127 | public void failure(RetrofitError error) { 128 | Toast.makeText(MainActivity.this, error.getMessage().toString(), Toast.LENGTH_LONG).show(); 129 | } 130 | }); 131 | break; 132 | 133 | case "Object with Nested Object": 134 | restClient.getService().getObjectWithNestedObject(new Callback() { 135 | @Override 136 | public void success(Student student, Response response) { 137 | String result = ""; 138 | result = "First name: " + student.first + 'n' + 139 | "Last name: " + student.last + 'n' + 140 | "Age: " + student.age + 'n' + 141 | "Sex: " + student.sex + 'n' + 142 | "Registered: " + student.registered + 'n' + 143 | "Favor. Color: " + student.favorites.color + 'n' + 144 | "Favor. Food: " + student.favorites.food + 'n' + 145 | "Favor. Sport: " + student.favorites.sport; 146 | 147 | 148 | tvResult.setText(result); 149 | } 150 | 151 | @Override 152 | public void failure(RetrofitError error) { 153 | Toast.makeText(MainActivity.this, error.getMessage().toString(), Toast.LENGTH_LONG).show(); 154 | } 155 | }); 156 | break; 157 | case "Object with Nested Arrays and Objects": 158 | restClient.getService().getObjectWithNestedArraysAndObject(new Callback() { 159 | @Override 160 | public void success(Student student, Response response) { 161 | String result = ""; 162 | /* result = "First name: " + student.first + 'n' + 163 | "Last name: " + student.last + 'n' + 164 | "Age: " + student.age + 'n' + 165 | "Sex: " + student.sex + 'n' + 166 | "Registered: " + student.registered + 'n'; 167 | 168 | if (student.interests.size() > 0) { 169 | for (int i = 0; i < student.interests.size(); i++) { 170 | result += "Array :[" + i + ']' + student.interests.get(i) + 'n'; 171 | } 172 | 173 | } 174 | 175 | 176 | result += 177 | "Favor. Color: " + student.favorites.color + 'n' + 178 | "Favor. Food: " + student.favorites.food + 'n' + 179 | "Favor. Sport: " + student.favorites.sport + 'n'; 180 | 181 | */ 182 | /*if (student.skills != null && student.skills.size() > 0) { 183 | for (int i = 0; i < student.skills.size(); i++) { 184 | result += "\n"+"category: " + student.skills.get(i).category+"\n"; 185 | if (student.skills.get(i).tests.size() > 0) { 186 | for (int j = 0; j < student.skills.get(i).tests.size(); j++) { 187 | result += "tests name: " + student.skills.get(i).tests.get(j).name + '\n' 188 | + "tests score: " + student.skills.get(i).tests.get(j).score + '\n'; 189 | } 190 | 191 | } 192 | } 193 | }*/ 194 | 195 | if (student.skills != null && student.skills.size() > 0) { 196 | for (int i = 0; i < student.skills.size(); i++) { 197 | result += "\n"+"category: " + student.skills.get(i).category+"\n"; 198 | if (student.skills.get(i).tests.size() > 0) { 199 | for (int j = 0; j < student.skills.get(i).tests.size(); j++) { 200 | result += "tests name: " + student.skills.get(i).tests.get(j).name + '\n' 201 | + "tests score: " + student.skills.get(i).tests.get(j).score + '\n'; 202 | } 203 | 204 | } 205 | } 206 | } 207 | 208 | tvResult.setText(result); 209 | } 210 | 211 | @Override 212 | public void failure(RetrofitError error) { 213 | Toast.makeText(MainActivity.this, error.getMessage().toString(), Toast.LENGTH_LONG).show(); 214 | } 215 | }); 216 | break; 217 | default: 218 | break; 219 | } 220 | 221 | 222 | } 223 | }); 224 | 225 | 226 | } 227 | 228 | /* @Override 229 | public boolean onCreateOptionsMenu(Menu menu) { 230 | // Inflate the menu; this adds items to the action bar if it is present. 231 | getMenuInflater().inflate(R.menu.menu_main, menu); 232 | return true; 233 | } 234 | 235 | @Override 236 | public boolean onOptionsItemSelected(MenuItem item) { 237 | // Handle action bar item clicks here. The action bar will 238 | // automatically handle clicks on the Home/Up button, so long 239 | // as you specify a parent activity in AndroidManifest.xml. 240 | int id = item.getItemId(); 241 | 242 | //noinspection SimplifiableIfStatement 243 | if (id == R.id.action_settings) { 244 | return true; 245 | } 246 | 247 | return super.onOptionsItemSelected(item); 248 | }*/ 249 | } -------------------------------------------------------------------------------- /app/src/main/java/com/herndon/webservicedataparse/RestClient.java: -------------------------------------------------------------------------------- 1 | package com.herndon.webservicedataparse; 2 | 3 | public class RestClient { 4 | //You need to change the IP if you testing environment is not local machine 5 | //or you may have different from what we have here 6 | private static final String URL = "http://instinctcoder.com/wp-content/uploads/2015/08/"; 7 | private retrofit.RestAdapter restAdapter; 8 | private StudentService studentService; 9 | 10 | public RestClient() 11 | { 12 | 13 | restAdapter = new retrofit.RestAdapter.Builder() 14 | .setEndpoint(URL) 15 | .setLogLevel(retrofit.RestAdapter.LogLevel.FULL) 16 | .build(); 17 | 18 | studentService = restAdapter.create(StudentService.class); 19 | } 20 | 21 | public StudentService getService() 22 | { 23 | return studentService; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/herndon/webservicedataparse/StudentService.java: -------------------------------------------------------------------------------- 1 | package com.herndon.webservicedataparse; 2 | 3 | import com.herndon.webservicedataparse.model.Student; 4 | 5 | import java.util.List; 6 | 7 | import retrofit.Callback; 8 | import retrofit.http.GET; 9 | 10 | public interface StudentService { 11 | // /So these are the list available in our WEB API and the methods look straight forward 12 | 13 | @GET("/Array.txt") 14 | public void getArray(Callback> items); 15 | 16 | @GET("/ArrayWithObjects.txt") 17 | public void getArrayWithObjects(Callback> callback); 18 | 19 | @GET("/Object.txt") 20 | public void getObject(Callback student); 21 | 22 | @GET("/ObjectWithNestedArray.txt") 23 | public void getObjectWithNestedArray(Callback student); 24 | 25 | @GET("/ObjectWithNestedObject.txt") 26 | public void getObjectWithNestedObject(Callback student); 27 | 28 | @GET("/ObjectWithNestedArraysAndObject.txt") 29 | public void getObjectWithNestedArraysAndObject(Callback student); 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/herndon/webservicedataparse/model/Favorites.java: -------------------------------------------------------------------------------- 1 | package com.herndon.webservicedataparse.model; 2 | 3 | public class Favorites { 4 | public String color; 5 | public String sport; 6 | public String food; 7 | 8 | } -------------------------------------------------------------------------------- /app/src/main/java/com/herndon/webservicedataparse/model/Skills.java: -------------------------------------------------------------------------------- 1 | package com.herndon.webservicedataparse.model; 2 | 3 | 4 | import java.util.List; 5 | 6 | /** 7 | * Created by Tan on 8/10/2015. 8 | */ 9 | //For Line 14 in JSON File 10 | public class Skills { 11 | public String category; 12 | public List tests; 13 | } -------------------------------------------------------------------------------- /app/src/main/java/com/herndon/webservicedataparse/model/Student.java: -------------------------------------------------------------------------------- 1 | package com.herndon.webservicedataparse.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by Tan on 8/10/2015. 7 | */ 8 | //For Line 1 in JSON File 9 | public class Student { 10 | public String name; 11 | public String first; 12 | public String last; 13 | public int age; 14 | public String sex; 15 | public Boolean registered; 16 | public List interests; 17 | public Favorites favorites; 18 | public List skills; 19 | 20 | } -------------------------------------------------------------------------------- /app/src/main/java/com/herndon/webservicedataparse/model/Tests.java: -------------------------------------------------------------------------------- 1 | package com.herndon.webservicedataparse.model; 2 | 3 | public class Tests { 4 | 5 | public String name; 6 | public double score; 7 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 |