From cbcc5a5e4c1edd4689c756a2548a5087201ee74e Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Sun, 22 Jan 2012 23:01:24 +0700 Subject: toJSON() --- src/com/juick/json/User.java | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/com/juick/json/User.java') diff --git a/src/com/juick/json/User.java b/src/com/juick/json/User.java index b4e0e7e8..43ee4803 100644 --- a/src/com/juick/json/User.java +++ b/src/com/juick/json/User.java @@ -24,10 +24,10 @@ import org.json.JSONObject; * * @author Ugnich Anton */ -public class User extends com.juick.User { +public class User { - public static User parseJSON(JSONObject json) throws JSONException { - User juser = new User(); + public static com.juick.User parseJSON(JSONObject json) throws JSONException { + com.juick.User juser = new com.juick.User(); juser.UID = json.getInt("uid"); juser.UName = json.getString("uname"); if (json.has("fullname")) { @@ -35,4 +35,23 @@ public class User extends com.juick.User { } return juser; } + + public static JSONObject toJSON(com.juick.User user) { + JSONObject json = new JSONObject(); + + try { + if (user.UID > 0) { + json.put("uid", user.UID); + } + if (user.UName != null) { + json.put("uname", user.UName); + } + if (user.FullName != null) { + json.put("fullname", user.FullName); + } + } catch (JSONException e) { + } + + return json; + } } -- cgit v1.2.3