2011-10-05 22 views
0

我试图使用Sencha触摸脚本标记代理,以便我可以使用远程网站上的JSON文件,但是我看到在Safari控制台中解析错误,即使我有验证JSON文件是否正确。Sencha触摸脚本标记代理JSON读取器解析错误

我的模型是这样的:

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新闻”, data.json:2SyntaxError:解析错误

任何帮助,在此,将不胜感激我一直在抓我的头几个小时就这一个了。

感谢阿龙

回答

0

经过多次试验和错误之后,我发现这不起作用,因为我的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); 
} 

?> 
0

尝试更改为此:

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

也不存在在JSON没有 '身份证'。

+0

感谢您的答复我改变了这一部分,现在收到此错误信息:数据视图需要第三方物流,存储和itemSelector配置进行定义 – MonkeyBlue

+0

@ llya139嗨感谢您的评论我有固定的错误我错过了{读者之后:但是我仍然得到解析错误?谢谢Aaron – MonkeyBlue