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

26783Re: [ydn-javascript] datasource JSON string problem

Expand Messages
  • WongTseng
    Mar 5, 2008
    • 0 Attachment
      Thanks a lot.
      But I wonder since javascript has eval( )  method which can evaluate the JSON string, why somebody ever bother to create this JSON string encoder.

      2008/3/2, Adam Moore <adamoore@...>:
      On Sat, Mar 01, 2008 at 11:00:55AM +0100, Satyam wrote:
      > The new JSON decoder, YAHOO.lang.JSON is more strict than the default
      > decoder included in the DataSource.  If you don't include the new JSON
      > decoder and let the DataSource handle it, it will probably take it.
      > The JSON standard (see sidebox in http://www.json.org/) says that all
      > identifiers should be strings (with quotes).  That allows for the
      > flexibility of having reserved words or otherwise questionable strings
      > as field identifiers, but does force you to enclose everything in
      > quotes.


      JSON is a subset of JavaScript, and the identifier requirement is one of
      rules an encoder must comply with in order to produce a compliant JSON
      string.  While is it acceptable for a decoder to try to parse a broken
      JSON string, it isn't acceptable for an encoder to produce one.  If you
      emit a JSON string, any decoder should be able to parse it.

      There are compliant encoders available for almost every common
      programming language, so you should not have to write your own anyway.
      Check out the bottom of json.org to find one.


      -Adam


      >   ----- Original Message -----
      >   From: WongTseng
      >   To: ydn-javascript@yahoogroups.com
      >   Sent: Saturday, March 01, 2008 2:54 AM
      >   Subject: [ydn-javascript] datasource JSON string problem

      >

      >       I have a question about the correct JSON string format that a
      >       datasource can receive through XHR. One thing puzzling me is
      >       that when I format the JSON string without double quotes around
      >       the attribute names, the datasource will raise a data error
      >       message.  for example, {name: "Tom"} // wrong, data error but if
      >       I put it like this, {"name" : "Toma"} // it's correct, data
      >       table displays it nicely.  So, what is the defference between
      >       these two kind of writting? Thanks.
      >
      >   -- Best Regards Tseng Wong




      --
      Best Regards
      Wong Tseng
    • Show all 7 messages in this topic