1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    4
    Vote Rating
    0
    StewartWeill is on a distinguished road

      0  

    Default Unanswered: JSON String with no root? How to retrieve values?

    Unanswered: JSON String with no root? How to retrieve values?


    I have a script that is encoding the json string. The url of that that is outputting this:
    Code:
    [
       {
          "title":"Example ",
          "quote":"Test quote lorem ipsum.",
          "url":"http:\/\/xxx.ca\/projects\/example\/"
       }
    ]
    How do I retrieve those values without there being a root to set the reader to?

    This is my store and I am not able to retrieve the values:
    Code:
    Ext.define('Sencha.store.Shows', {
        extend: 'Ext.data.Store',
        requires: ['Sencha.model.Show'],
    
        config: {
            model: 'Sencha.model.Show',
            proxy: {
                    type: 'scripttag',
                    url : 'http://xxx.ca/wp-content/themes/themename/includes/json-feed.php',
                    reader: {
                        type: 'json',
                    },
            },
            autoLoad: true
        }
    });
    BTW: This warning did show up in my debug console: "Resource interpreted as Script but transferred with MIME type application/json."

    Thanks in advance for any help

  2. #2
    Sencha User
    Join Date
    Apr 2012
    Posts
    4
    Vote Rating
    0
    StewartWeill is on a distinguished road

      0  

    Default added a root, but still no result

    added a root, but still no result


    OK so this is now my valid JSON(now has a root):

    Code:
    {
       "projs":{
          "title":"Example ",
          "quote":"Test quote lorem ipsum.",
          "url":"http:\/\/xxx.ca\/projects\/example\/"
       }
    }
    And my store has been updated to include the rootProperty: 'projs'. This exact setup has worked for me before (when I was using Wordpress JSON API to output the json which has the same syntax as here now with the root). However I am getting no data through. I am now getting a Syntax Error saying that there's an unexpected token ':' in the callback.

    Code:
    Ext.define('Sencha.store.Shows', {
        extend: 'Ext.data.Store',
        requires: ['Ext.data.proxy.JsonP', 'Ext.data.ScriptTagProxy', 'Sencha.model.Show'],
    
        config: {
            model: 'Sencha.model.Show',
            proxy: {
                    type: 'scripttag',
                    url : 'http://xxx.ca/wp-content/themes/themename/includes',
                    reader: {
                        type: 'json',
                        rootProperty: 'projs',
                    },
            },
            autoLoad: true
        }
        
    });
    Does this make sense to anyone?

    Again any help would be greatly appreciated.

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    4
    Vote Rating
    0
    StewartWeill is on a distinguished road

      0  

    Default fyi I have fixed it

    fyi I have fixed it


    I found after much digging around that the server side had to wrap the json encoding inside this callback function:

    Code:
    $callback = $_REQUEST['callback']; 
    
    if ($callback) { 
        header('Content-Type: text/javascript'); 
        echo $callback . '(' . json_encode(array('projs'=>$jsonevents)) . ');'; 
    } else { 
        header('Content-Type: application/x-json'); 
        echo json_encode(array('projs'=>$jsonevents)); 
    }
    ?>
    Where $jsonevents is the array I created from the posts sql query in wordpress.

    I could have sworn I read that this all happened automatically, but I guess I might have confused that with jasonp - not sure. Anyways thanks to the dudes in this thread http://www.sencha.com/forum/showthre...end-script-tag check it out if you are experiencing scipttag or jsonp callback issues.

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar