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

Re: json.parse returns false or error with valid strings on server-side JS

Expand Messages
  • dnc_octopus
    ... Ok. I build an object like this on the client side just for testing: function fazJSON() { var mObj = new Object; mObj.Time = new Date().getTime();
    Message 1 of 5 , Apr 6, 2006
    • 0 Attachment
      --- In json@yahoogroups.com, Lindsay <lindsay@...> wrote:
      >
      > dnc_octopus wrote:
      > > Hi.
      > >
      > >
      > > I get the stringified text and pass it to JSON.parse. False is
      > > returned or an error saying the object does not support this method.
      > >
      >
      > Post some json that fails and you source that calls the parser.
      >
      >
      > --
      > Lindsay
      >

      Ok.
      I build an object like this on the client side just for testing:
      function fazJSON()
      {
      var mObj = new Object;
      mObj.Time = new Date().getTime();
      mObj.Data = new Date().toUTCString();
      return JSON.stringify(mObj);
      }

      Then I pass this object to AJAX.Request (from prototype lib):
      new Ajax.Request ('teste.asp',
      {
      method: 'get',
      parameters: 'pedido=' + objJSN,
      onSuccess: procResp,
      onFailure: procErro
      }
      );


      On the server I get the request using the QueryString, and pass it to
      JSON.parse:

      strReq = Request.QueryString("pedido");
      respObj = JSON.parse(strReq);
      if(respObj == false) {
      Response.Write('JSON returned False');
      Response.End;
      }

      The following are examples of json strings (produced by JSON) that
      return false from JSON.parse on the server:
      {"Time":1144349903406,"Data":"Thu, 06 Apr 2006 18:58:23 GMT"}
      {"Data":"Thu, 06 Apr 2006 19:05:50 GMT"}
      {"url":{"hash":"","host":"dnc1","hostname":"dnc1","href":"http://dnc1/evsig2/teste.html","pathname":"/evsig2/teste.html","port":"","protocol":"http:","search":""}}

      But if I eval the strings it's ok.

      Also, a last detail. On the server page I use:
      <%@ language="javascript"%>
      <!--#include virtual="/evsig2/server/json.asp"-->
      <%
      ...rest of the program goes here...
      %>

      If there's any other info that's relevant just let me know.
      Duarte
    • Mark Ingalls
      I don’t see where you are calling fazJSON to stringify the object, but I’ll assume that objJSN is the stringified version of an object. I had to wrap the
      Message 2 of 5 , Apr 10, 2006
      • 0 Attachment
        I don’t see where you are calling fazJSON to stringify the object, but I’ll
        assume that objJSN is the stringified version of an object.



        I had to wrap the stringified object in a call to encodeURIComponent to get
        the object roundtrip successfully. YMMV



        I have a working example that uses two .asp pages and some supporting js
        files. If you’d like them, please let me know and I’ll send them.



        Thanks,

        Mark



        _____

        Original message:

        Ok.
        I build an object like this on the client side just for testing:
        function fazJSON()
        {
        var mObj = new Object;
        mObj.Time = new Date().getTime();
        mObj.Data = new Date().toUTCString();
        return JSON.stringify(mObj);
        }

        Then I pass this object to AJAX.Request (from prototype lib):
        new Ajax.Request ('teste.asp',
        {
        method: 'get',
        parameters: 'pedido=' + objJSN,
        onSuccess: procResp,
        onFailure: procErro
        }
        );


        On the server I get the request using the QueryString, and pass it to
        JSON.parse:

        strReq = Request.QueryString("pedido");
        respObj = JSON.parse(strReq);
        if(respObj == false) {
        Response.Write('JSON returned False');
        Response.End;
        }

        The following are examples of json strings (produced by JSON) that
        return false from JSON.parse on the server:
        {"Time":1144349903406,"Data":"Thu, 06 Apr 2006 18:58:23 GMT"}
        {"Data":"Thu, 06 Apr 2006 19:05:50 GMT"}
        {"url":{"hash":"","host":"dnc1","hostname":"dnc1","href":"http://dnc1/evsig2
        /teste.html","pathname":"/evsig2/teste.html","port":"","protocol":"http:","s
        earch":""}}

        But if I eval the strings it's ok.

        Also, a last detail. On the server page I use:
        <%@ language="javascript"%>
        <!--#include virtual="/evsig2/server/json.asp"-->
        <%
        ..rest of the program goes here...
        %>

        If there's any other info that's relevant just let me know.
        Duarte




        _____



        [Non-text portions of this message have been removed]
      • dnc_octopus
        Mark, Your assumption is correct. I ll try encodeURIComponent before using parse and see what happens. Thanks for your help! Duarte ... but I ll ... to get ...
        Message 3 of 5 , Apr 14, 2006
        • 0 Attachment
          Mark,

          Your assumption is correct.

          I'll try encodeURIComponent before using parse and see what happens.

          Thanks for your help!
          Duarte

          --- In json@yahoogroups.com, "Mark Ingalls" <mark_ingalls@...> wrote:
          >
          > I don't see where you are calling fazJSON to stringify the object,
          but I'll
          > assume that objJSN is the stringified version of an object.
          >
          >
          >
          > I had to wrap the stringified object in a call to encodeURIComponent
          to get
          > the object roundtrip successfully. YMMV
          >
          >
          >
          > I have a working example that uses two .asp pages and some supporting js
          > files. If you'd like them, please let me know and I'll send them.
          >
          >
          >
          > Thanks,
          >
          > Mark
          >
          >
          >
          > _____
          >
          > Original message:
          >
          > Ok.
          > I build an object like this on the client side just for testing:
          > function fazJSON()
          > {
          > var mObj = new Object;
          > mObj.Time = new Date().getTime();
          > mObj.Data = new Date().toUTCString();
          > return JSON.stringify(mObj);
          > }
          >
          > Then I pass this object to AJAX.Request (from prototype lib):
          > new Ajax.Request ('teste.asp',
          > {
          > method: 'get',
          > parameters: 'pedido=' + objJSN,
          > onSuccess: procResp,
          > onFailure: procErro
          > }
          > );
          >
          >
          > On the server I get the request using the QueryString, and pass it to
          > JSON.parse:
          >
          > strReq = Request.QueryString("pedido");
          > respObj = JSON.parse(strReq);
          > if(respObj == false) {
          > Response.Write('JSON returned False');
          > Response.End;
          > }
          >
          > The following are examples of json strings (produced by JSON) that
          > return false from JSON.parse on the server:
          > {"Time":1144349903406,"Data":"Thu, 06 Apr 2006 18:58:23 GMT"}
          > {"Data":"Thu, 06 Apr 2006 19:05:50 GMT"}
          >
          {"url":{"hash":"","host":"dnc1","hostname":"dnc1","href":"http://dnc1/evsig2
          >
          /teste.html","pathname":"/evsig2/teste.html","port":"","protocol":"http:","s
          > earch":""}}
          >
          > But if I eval the strings it's ok.
          >
          > Also, a last detail. On the server page I use:
          > <%@ language="javascript"%>
          > <!--#include virtual="/evsig2/server/json.asp"-->
          > <%
          > ..rest of the program goes here...
          > %>
          >
          > If there's any other info that's relevant just let me know.
          > Duarte
          >
          >
          >
          >
          > _____
          >
          >
          >
          > [Non-text portions of this message have been removed]
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.