i have the next situation. I want to obtain atributes from a User class , which contains atributes in the formats: Date, String, Name. Where Name is another class i created before which contains FirstName and LastName Strings. So, i have to do httprequest to my REST server and im doing this
protected static ArrayList<User> obtieneAmigos(int id) {
// TODO Auto-generated method stub
HttpClient httpClient = new DefaultHttpClient();
HttpGet del = new HttpGet("http://192.168.0.19/user/:"+id+"/friends/confirmed" );//Se obtienen los datos de la url del usuario
del.setHeader("content-type", "application/json");
ArrayList<User> friends =new ArrayList<User>();
try {
HttpResponse resp = httpClient.execute(del);
String respStr = EntityUtils.toString(resp.getEntity());
JSONArray respJSON = new JSONArray(respStr);
for(int i=0; i<respJSON.length();i++){
JSONObject objeto = respJSON.getJSONObject(i);
User friend = new User();
friend.setName(objeto.getString("FirstName"));//Error
friend.setBirthDate();//I dont know how to parse it to string
friends.add(friend);
}
return friends;
} catch (Exception ex) {
Log.e("ServicioRest", "Error!", ex);
}
return friends;
}
I need to know some things, first, how to obtain from JSON request in addition to Strings, another objects as my Name class. Second, how to parse or obtain the BirthDate as Date and no as String. And finally, another question. How is it parses Date to String or String to Date?
Clarification: The response comes formated as "user" with the atributes of this class. I want to do something as this: friend.setName(objeto.getName()); or friend.getName().setFirstName(objeto."getObject()."getString("FirstName")); where getObject is invented by me for this clarificatioin. Thanks.