2011-10-05 21 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