Loading ...
Sorry, an error occurred while loading the content.

toJSONString() isn't working like I'd expect it to.

Expand Messages
  • Scott Chapman
    Here s a strange situation to me. I m new to Javascript and so I expect I m missing something here. // Using GoogleMaps API to return the bounds of a map: var
    Message 1 of 1 , Jun 30, 2006
    • 0 Attachment
      Here's a strange situation to me. I'm new to Javascript and so I expect I'm missing something here.

      // Using GoogleMaps API to return the bounds of a map:

      var mapBounds = map.getBounds();
      mapBounds.toJSONString()

      // returns this:
      // {"s":{"lo":0.7426913579077786,"hi":0.824136934929629},"o":{"lo":-2.1945512646688954,"hi":-2.098677465426043}}

      // Why doesn't it return:
      // [{"lat": 44.94141, "lng": -123.034286, "id": 1}, {"lat": 44.052219, "lng": -123.086548, "id": 2}]
      //?

      // If I use escape(mapBounds) instead, it arrives at the server like this:
      // ({"lat": 44.94141, "lng": -123.034286, "id": 1}, {"lat": 44.052219, "lng": -123.086548, "id": 2})
      // I can replace the paren's with square brackets and convert it as a JSON string.

      I don't understand why escaping it provides a (nearly) proper representation but toJSONString doesn't. How do I make
      this work correctly?

      Scott
    Your message has been successfully submitted and would be delivered to recipients shortly.