Sencha Touch Script Tag Proxy JSON Reader解析错误

Sencha Touch Script Tag Proxy JSON Reader Parse Error

本文关键字:Reader 错误 JSON Proxy Touch Script Tag Sencha      更新时间:2023-09-26

我正在尝试使用Sencha Touch脚本标签代理,以便我可以在远程网站上使用JSON文件,但是我在Safari控制台看到解析错误,即使我已经验证了JSON文件是正确的。

My Model is this

    Ext.regModel('NoteNewsModel', {
    idProperty: 'id',
    fields: [
        { name: 'id', type: 'int' },
        { name: 'title', type: 'string' },
        { name: 'description', type: 'string' }
        // { name: 'icon', type: 'string' }
    ]
});    

我的商店代码是这样的:

Ext.regStore('NotesNewsStore', {
    model: 'NoteNewsModel',
    proxy: {
        type: 'scripttag',
        url: 'myjsonurl',
        reader: new Ext.data.JsonReader ({
            type: 'json',
            root: 'entries'
        })
    },
    autoLoad: true
 });

以下是远程服务器上JSON文件的一部分:

{
 "title":"json news",
 "link":"https://myurl.com/json-news.html",
 "description":"",
 "language":"en",
 "copyright":"my domain",
 "ttl":"120",
 "entries":[
    {
     "title":"SmarterMail Upgrade",
     "link":"https://mydomain.com/122.html",
     "date":"1316414335",
     "guid":"https://mydomain.com/122.html",
     "author":"flank plank",
     "description":"test entry",
     "introtext":"testing the intro text."
    }
  ]
}

最后,我在Safari控制台看到的错误显示在第一行

下面

"标题":json消息",数据。json:2SyntaxError:解析错误

任何帮助在这将是感激我已经抓耳挠腮几个小时在这个问题上了。

谢谢亚伦

试着这样修改:

reader: {
            type: 'json',
            root: 'entries'
        }

也不是说json中没有'id' .

经过多次尝试和错误后,我发现由于JSON文件没有正确格式化,这不起作用。

我遵循这个例子:http://www.sencha.com/learn/legacy/Tutorial:Creating_JSON_Data_in_PHP

在我的本地服务器上使用这段代码,它现在工作得很好。
<?php 
$link = mysql_pconnect("server", "user", "password") or die("Could not connect");
mysql_select_db("database") or die("Could not select database");
$arr = array();
$rs = mysql_query("SELECT * FROM news");
while($obj = mysql_fetch_object($rs)) {
    $arr[] = $obj;
}
$callback = $_REQUEST['callback'];
if ($callback) {
    header('Content-Type: text/javascript');
    echo $callback . '(' . json_encode($arr) . ');';
} else {
    header('Content-Type: application/x-json');
    echo json_encode($arr);
}
?>