Results 1 to 4 of 4

Thread: Ext.decode does not work

  1. #1
    Sencha User
    Join Date
    Jan 2009
    Posts
    79

    Default Ext.decode does not work

    Hello.

    I am kind new in Touch, but I have some experience in ExtJs.

    I was trying to use the Ext.decode or Ext.utils.JSON.decode as in following example

    Code:
    var stringData = "{date: 'Friday 03rd of August 2007 02:47:09 PM'}";
           try {
            var jsonData = Ext.decode(stringData);
            alert('Success');
            // You can do anything with jsonData if you want.
           }
           catch (err) {
            alert('ERROR');
           }
    But I got always the Error message, so there might be some problem with the decode function?

    Thank you very much!

  2. #2

    Default

    Ext.decode decodes JSON. JSON requires double-quotes around the keys and string values. Just use
    Code:
    var stringData = '{"date": "Friday 03rd of August 2007 02:47:09 PM"}';
    instead, then it should work.

    Also see the JSON article on Wikipedia.

    HTH,

    Timo

  3. #3
    Sencha User
    Join Date
    Jun 2009
    Location
    Italy
    Posts
    1,395

    Default

    Hi lakilevi,
    that's because your is not a valid JSON string.
    Try this

    Code:
    var a;
    Ext.setup({
        onReady: function() {
    
            var stringData = '{"date": "Friday 03rd of August 2007 02:47:09 PM"}';
           try {
            var jsonData = Ext.decode(stringData);
            alert('Success');
            console.log(jsonData);
            // You can do anything with jsonData if you want.
           }
           catch (err) {
            alert('ERROR');
           }
    
        }
    
    });
    In these cases, I always suggest to validate the JSON using JSONLint.

    Hope this helps.

  4. #4
    Sencha User
    Join Date
    Jan 2009
    Posts
    79

    Default

    Thank you very much!
    You are right, it is working now.

    But anyway, it is wired, becuase in case of ExtJs 1.x-3.x I made lot of jason decodes without any double-quotes. All my ajax requestes returned jason encoded data, without quotes, and in extjs it was decoded with success.

    Thank you very much again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •