@@ -110,7 +110,7 @@ AndroidNetworking.get("http://api.localhost.com/{pageNumber}/test")
110
110
public void onError (ANError error ) {
111
111
// handle error
112
112
}
113
- });
113
+ });
114
114
```
115
115
### Making a POST Request
116
116
``` java
@@ -173,6 +173,54 @@ AndroidNetworking.post("http://api.localhost.com/postFile")
173
173
}
174
174
});
175
175
```
176
+
177
+ ### Using it with your own JAVA Object - JSON Parser
178
+ ```
179
+ /*--------------Example One -> Getting the userList----------------*/
180
+ AndroidNetworking.get("http://api.localhost.com/getAllUsers/{pageNumber}")
181
+ .addPathParameter("pageNumber", "0")
182
+ .addQueryParameter("limit", "3")
183
+ .setTag(this)
184
+ .setPriority(Priority.LOW)
185
+ .build()
186
+ .getAsParsed(new TypeToken<List<User>>() {}, new ParsedRequestListener<List<User>>() {
187
+ @Override
188
+ public void onResponse(List<User> users) {
189
+ // do anything with response
190
+ Log.d(TAG, "userList size : " + users.size());
191
+ for (User user : users) {
192
+ Log.d(TAG, "id : " + user.id);
193
+ Log.d(TAG, "firstname : " + user.firstname);
194
+ Log.d(TAG, "lastname : " + user.lastname);
195
+ }
196
+ }
197
+ @Override
198
+ public void onError(ANError anError) {
199
+ // handle error
200
+ }
201
+ });
202
+ /*--------------Example Two -> Getting an user----------------*/
203
+ AndroidNetworking.get("http://api.localhost.com/getAnUser/{userId}")
204
+ .addPathParameter("userId", "1")
205
+ .setTag(this)
206
+ .setPriority(Priority.LOW)
207
+ .build()
208
+ .getAsParsed(new TypeToken<User>() {}, new ParsedRequestListener<User>() {
209
+ @Override
210
+ public void onResponse(User user) {
211
+ // do anything with response
212
+ Log.d(TAG, "id : " + user.id);
213
+ Log.d(TAG, "firstname : " + user.firstname);
214
+ Log.d(TAG, "lastname : " + user.lastname);
215
+ }
216
+ @Override
217
+ public void onError(ANError anError) {
218
+ // handle error
219
+ }
220
+ });
221
+ /*-- Note : TypeToken and getAsParsed is important here--*/
222
+ ```
223
+
176
224
### Downloading a file from server
177
225
``` java
178
226
AndroidNetworking . download(url,dirPath,fileName)
@@ -489,7 +537,6 @@ AndroidNetworking.initialize(getApplicationContext(),okHttpClient);
489
537
### TODO
490
538
* Integration with other library
491
539
* And of course many many features and bug fixes
492
- * Json Parser
493
540
494
541
### CREDITS
495
542
* [ Square] ( https://square.github.io/ ) - As both [ OkHttp] ( http://square.github.io/okhttp/ ) and [ Okio] ( https://github.com/square/okio )
0 commit comments