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

662json object from cookie

Expand Messages
  • mark
    Jan 15, 2007
    • 0 Attachment
      I am trying to get JSON object from a JSON string in a cookie. When I
      convert the string read from cookie, i still get a string and not a JSON
      object. So i did an eval on the string again and I get the JSON object fine.
      is this the right way to do this?
      what am i doing wrong?

      thanks
      mark


      here is what i do:
      var json_text=getcookie('sub_options');
      var json_text_string = eval('(' + json_text + ')');
      var options_list= eval('(' + json_text_string + ')');

      //to get cookie
      function getcookie(cookiename) {
      var cookiestring=""+document.cookie;
      var index1=cookiestring.indexOf(cookiename);
      if (index1==-1 || cookiename=="") return "";
      var index2=cookiestring.indexOf(';',index1);
      if (index2==-1) index2=cookiestring.length;
      return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
      }


      [Non-text portions of this message have been removed]
    • Show all 13 messages in this topic