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

Re: [json] Re: [question] parse json with ajax

Expand Messages
  • Michal Migurski
    ... This should help: eval( var responsejson = ( + responsetext + ); ); alert(responsejson[ depth1 ][ depth2 ][ depth3 ]; ... Yes. -mike. ... michal
    Message 1 of 7 , Aug 15, 2007
    • 0 Attachment
      On Aug 14, 2007, at 11:34 PM, genzoeri wrote:
      > I will use this for my AJAX. Using responsetext properties from XHR.
      > :) ok,then how to parse, {"depth1":{"depth2":{"depth3":"content"}}} ??
      > btw, thank you for your response. I am glad, I am on the right place.

      This should help:
      eval("var responsejson = (" + responsetext + ");");
      alert(responsejson['depth1']['depth2']['depth3'];



      On Aug 14, 2007, at 11:58 PM, Mark Ireland wrote:
      > Key names must be quoted and cant start with a number?Is that right?

      Yes.

      -mike.

      ----------------------------------------------------------------
      michal migurski- contact info and pgp key:
      sf/ca http://mike.teczno.com/contact.html
    • Philip Tellis
      ... Ugh, don t do that. Apart from screwing with the scope of responsejson, it also causes a security problem, and it s overkill. If you must use eval, do it
      Message 2 of 7 , Aug 15, 2007
      • 0 Attachment
        On 15/08/07, Michal Migurski <mike-jsonphp@...> wrote:
        >
        > This should help:
        > eval("var responsejson = (" + responsetext + ");");
        > alert(responsejson['depth1']['depth2']['depth3'];

        Ugh, don't do that. Apart from screwing with the scope of
        responsejson, it also causes a security problem, and it's overkill.
        If you must use eval, do it this way:

        var responsejson = eval( "(" + o.responseText + ")" );

        That won't take away the security problems with eval, but it will make
        sure that responsejson is in current scope.
      Your message has been successfully submitted and would be delivered to recipients shortly.