At  first, I thought I embarassingly overlooked I was quoting the data
by myself, but nevertheless (strangely) I still get the same behaviour:

in the template:
var routes = ${routes};
in rendered page:
var routes = [["{\"longitude\":38.94441,\"latitude\":47.203542}",...

The corresponding code is now:
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);
            }
            jsonRoutes.put(jsonRoutePoints);
        }
        return jsonRoutes.toString();
}
> jsonRoutePoints.put(jsonPoint)

> 2010/1/7 Yury Luneff <bitter...@ya.ru>:
>> 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
>>
>>






-- 
С уважением,
 Yury                          mailto:bitter...@ya.ru


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

Reply via email to