I am trying to convert a java object to json using Gson. But when i tried printing it out.I got this JSON
{"user":"{\"email\":\"[email protected]\",\"lastName\":\"Las\",\"name\":\"amy\",\"password\":\"qwe123\",\"phone\":\"8901245244\"}"}
I tried
s.replace("\\"", "\"") but neither it helps nor its a good approach.
Further I have gone through various links but answers are ambiguous.
This is my User class toString method
public class User implements Serializable
{ ...
@Override
public String toString()
{ return "User{" +
"first_name:" + name+
", last_name:" + lastName+
", mobile:" + phone+
", email:" + email+
", password:" + password+
"}";
}
I guess its not even calling this toString method.
and here is how am I converting to JSON
User u=new User(name,lastName,email,phone,password);
Gson userGson=new GsonBuilder().create();
String jo=userGson.toJson(u);
JSONObject params=new JSONObject();
params.put("user",jo);
Log.e("in register",params.toString());
Any help is appreciated.