Hello!

I have following code:
public String getRoutes() {
        List<Route> routes = routeDAO.findAll();
        JSONArray jsonRoutes = new JSONArray();

        for (Route route : routes) {
            JSONArray jsonRoutePoints = new JSONArray();
            for (RoutePoint point : route.getPoints()) {
                JSONObject jsonPoint = new JSONObject();
                jsonPoint.put("latitude", point.getLatitude());
                jsonPoint.put("longitude", point.getLongitude());
                jsonRoutePoints.put(jsonPoint.toString());
            }
            jsonRoutes.put(jsonRoutePoints);
        }
        return jsonRoutes.toString();
    }

    Goal is to get a JSON object that is accesible like
    "routes[0][0].latitude". But nested JSON objects are quoted by "\"" when the
    jsonRoutes.toString() is called.

    I receive an array of strings like 
"{"longitude":38.94441,"latitude":47.203542}"
    for each jsonPoint variable instead of    
{"longitude":38.94441,"latitude":47.203542}
    for each one.

    This happens because JSONObject's toString doesn't treat its
    nested instances the way it probably should do. If jsonobject has
    nested object the whole nested object should not be escaped.

    I guess the problem relies somewhere around
    JSONObject.valueToString method.

    Or am I using JSONObject/JSONArray in a wrong way?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to