Results 1 to 4 of 4

Thread: Having problem with decoding a Json response

  1. #1

    Default Having problem with decoding a Json response

    Hello everyone.

    I am running into an issue that should be trivial but for some reason I can't get it to work. Let's say I have the following (string) data:

    var dataString = '[{content:"Please remember to take your medication", source:"T. Spencer"}, {content:"Please setup an office consultation", source:"T. Spencer"}]';

    If I want to create a Json object (array) from it, in Ext JS, I used to do:

    var data = Ext.decode(dataString);

    and then data would be a JS object. But in Sencha Touch, this last call doesn't work. Could some one please tell me what I am doing wrong? My final goal is to pass this data object to a template like the following:

    '<tpl for=".">',

    Many thanks,

  2. #2
    Ext JS Premium Member
    Join Date
    Nov 2007
    Cambridge UK

    Default More info required

    Could the full stop be the problem in "T. Spencer" ?

    If the dataString is originated from JavaScript why not make it an object in the first instance?

    Where does dataString come from ?

  3. #3

    Default More Info inside

    My earlier post was a simplified version of my application so here is a more detailed account of that. In my application, I make an Ajax call (to the same server, so no cross-site scripting issue) like the following:

        url : 'getNotificationsJson?0=100',
        method : 'GET',
        success : function(responseObject) {
            var jsonContent = responseObject.responseText;
            var json = Ext.decode(jsonContent, true);
        failure : function() {
            alert('Status','Unable to show records at this time. Please try again later.');
    The "messagCard" above is a component with a template:

    var messageCard = new Ext.Component({
        title: 'Messages',
        iconCls: 'favorites',
        cls: 'message',
        scroll: 'vertical',
        tpl: [
            '<tpl for=".">',
    So the response to the ajax call is retrieved, the textual content is extracted and then I want to create a JS object from that to update the template. The textual content of the ajax response is what I had noted before and I have verified that it gets there correctly but when I try to decode that, it fails. I did test removing the "." in "T. Spencer" and still have the same issue.

    My goal is to populate my template with the result returned from the ajax call so if there is a better way to do that, I am open to alternatives.

    Many thanks

  4. #4
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Sydney, Australia


    It's not valid JSON, you need to quote the identifiers. is very useful
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

Similar Threads

  1. [INFOREQ]Json decoding results in error in FireFox
    By Snape in forum Ext 3.x: Help & Discussion
    Replies: 10
    Last Post: 25 Mar 2010, 7:50 AM
  2. [2.2] JSON decoding is broken on some unicode chars
    By rslinckx in forum Ext 2.x: Bugs
    Replies: 11
    Last Post: 10 Sep 2009, 2:51 AM
  3. [SOLVED]Decoding json string
    By neenhouse in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 3 Apr 2008, 8:31 AM
  4. decoding json string
    By mzagzoog in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 1 Mar 2008, 6:17 AM
  5. Having trouble decoding a json array
    By BarryOg in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 8 Jul 2007, 4:08 AM

Posting Permissions

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