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

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

Expand Messages
  • Mark Ingalls
    Apr 10, 2006
      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]
    • Show all 5 messages in this topic