2013-02-05 165 views
2

我們以JSON格式獲得響應,但我們無法獲取並打印數據。通過存儲從JSON數組中獲取JSON響應數據

var dstore = Ext.getStore('DomesticStore'); 
dstore.sync(); 
dstore.load(); 
console.log(dstore.getData().items); 
// this line prints the output but unable to fetch inside array data. 
+0

你可以試試看看console.log(dstore.getData()。items [0] .raw);'在工作嗎?如果你的數組有數據,這將打印一些東西 – ThinkFloyd

+0

另外,請發佈從服務器返回的JSON數據樣本,格式必須非常具體。 – jakerella

回答

1

我有一個獲取JSON數據的應用程序。 當你讓商店打電話的方法。然後通過使用記錄數組訪問數據。

var Store1 = Ext.getStore('DomesticStore').on('load', function (store, records, successful, operation, eOpts) { 
     if(successful == false){ 
      console.log("Could not load store. "); 
     } 
     var e; 

     for (var i = 0; i < records.length; i++) { 
      e = records[i]; 
      console.log(e.get('elementname')); 
     } 
}); 

這將通過JSON數組並獲取字段名稱的每個值。

我的JSON數據看起來像這樣

{ 
    "countries": [ 
     { 
      "name": "United States", 
      "2001": 128500000, 
      "2002": 141800000, 
      "2003": 160637000, 
      "2004": 184819000, 
      "2005": 203700000, 
      "2006": 229600000, 
      "2007": 249300000, 
      "2008": 261300000, 
      "2009": 274300000, 
      "2010": 278900000, 
      leaf: true 
     } 
    ] 
} 

我使用該代碼從記錄數組,然後每名場得到每一個國家。