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/Place.java | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/com/juick/json/Place.java') diff --git a/src/com/juick/json/Place.java b/src/com/juick/json/Place.java index 63a5929c..4e3e5579 100644 --- a/src/com/juick/json/Place.java +++ b/src/com/juick/json/Place.java @@ -25,10 +25,10 @@ import org.json.JSONObject; * * @author Ugnich Anton */ -public class Place extends com.juick.Place { +public class Place { - public static Place parseJSON(JSONObject json) throws JSONException { - Place jplace = new Place(); + public static com.juick.Place parseJSON(JSONObject json) throws JSONException { + com.juick.Place jplace = new com.juick.Place(); jplace.pid = json.getInt("pid"); jplace.lat = json.getDouble("lat"); @@ -55,4 +55,26 @@ public class Place extends com.juick.Place { return jplace; } + + public static JSONObject toJSON(com.juick.Place place) { + JSONObject json = new JSONObject(); + + try { + if (place.pid > 0) { + json.put("pid", place.pid); + } + if (place.lat >= -90 && place.lat <= 90) { + json.put("lat", place.lat); + } + if (place.lon >= -180 && place.lon <= 180) { + json.put("lon", place.lon); + } + if (place.name != null) { + json.put("name", place.name); + } + } catch (JSONException e) { + } + + return json; + } } -- cgit v1.2.3