1

I have been searching the web about this problem and have not been very lucky.

I am using symfony to retrieve data from the database to load in to a extjs library. My problem is when loading the data, an error occurs saying "Ext.Error: You're trying to decode an invalid JSON String"

I queried the database correctly because it returns a set of data. The problem I think is with converting the array to json format.

Here is what it display when debugging my returned json format:

returned json format

and my code to that is:

  public function executeGetData(sfWebRequest $request)
  {
      $SQL = " SELECT sked.id, sked.program_id, sked.agentname,
            sked.customername, sked.customercontact, sked.callback_dt,
            sked.callback_dt AS date_closed
            FROM schedule sked LIMIT 5";

$Doctrine_Manager = Doctrine_Manager::getInstance()->getConnection('callback_tracker');
$result = $Doctrine_Manager->fetchAll($SQL);

$final = array("evts" => $result);

$finalJson = json_encode($final);
echo $finalJson;

My Event Store:

   var eventStores = Ext.create('Extensible.calendar.data.EventStore', {
//autoLoad: true,
id: 'calStore',
proxy: {
    type: 'rest',
    url: '/home/GetData',
    //appendId: false,
    method: 'POST',
    reader: {
    type: 'json',
    root: 'evts'
    },

    writer: {
    type: 'json',
    nameProperty: 'mapping'
    },

    listeners: {
    exception: function(proxy, response, operation, options){
        var msg = response.message ? response.message : Ext.decode(response.responseText).message;
        // ideally an app would provide a less intrusive message display
        Ext.Msg.alert('Server Error', msg);
    }
    }
},

listeners: {
    'write': function(store, operation){
    var title = Ext.value(operation.records[0].data[Extensible.calendar.data.EventMappings.Title.name], '(No title)');

    console.debug('Operation Action = ' + operation.action);
    switch(operation.action){
        case 'create': 
        //Extensible.example.msg('Add', 'Added "' + title + '"');
        break;
        case 'update':
        //Extensible.example.msg('Update', 'Updated "' + title + '"');
        break;
        case 'destroy':
           //Extensible.example.msg('Delete', 'Deleted "' + title + '"');
        break;
    }
    }
}
});

I load it afterRender of the Calendar.BTW, the library I am using is Extensible Calendar.

What is the problem here? Is it the json format? how do you convert this?

j0k
  • 22,600
  • 28
  • 79
  • 90
oneofakind
  • 552
  • 17
  • 41
  • Have you tried validating your JSON with a JSON validator? Lets first find the root of your problem. – Johan Haest Oct 20 '12 at 11:57
  • I tried some online Json Validator and instead of a one line json that was displayed to me the validator displyed with tabbing and new lines. I am using json_encode() why can it not format it that way? – oneofakind Oct 22 '12 at 01:51
  • 1
    Use http://jsonlint.com/ If you get: "Valid JSON" you're JSON shouldn't be the problem. – Johan Haest Oct 22 '12 at 07:01
  • but, my json result came from a query. What will put in the jsonlint.com? the echo or print of the json_encode? tested it and it shows valid.hmmmmm what could be the problem.. – oneofakind Oct 22 '12 at 07:23
  • the full string of what your screenshot shows under "Here is what it display when debugging my returned json format:" – Johan Haest Oct 22 '12 at 07:25
  • tested it and it shows valid..hhmmmm...what could be the problem with this then.. – oneofakind Oct 22 '12 at 07:27

0 Answers0