存储使用javascript返回的json数据

存储使用javascript返回的json数据,javascript,jquery,Javascript,Jquery,我通过ajax调用重新调整了json字符串 $.ajax({ type: 'GET', url: quoteURL, dataType: 'json', timeout: 10000, crossDomain: true, success: function(result) { /// required code

我通过ajax调用重新调整了json字符串

$.ajax({
            type: 'GET',
            url: quoteURL,
            dataType: 'json',
            timeout: 10000,
            crossDomain: true,
                 success: function(result) {
                /// required code       
               }

});
服务器返回的json响应为

{
   _emptyscopedata: [
      {},
      {}
   ],
   errMsgBuffer: {
      errMsg: ''
   },
   descriptor: [
      {
         template: 'projects/mobile/market/mostactives.xsl',
         componentname: 'getmostactives'
      },
      {
         template: '',
         componentname: 'quotelist'
      }
   ],
   'invest.mostactive': {
      MoverExchange: 'NSDQ',
      MoverType: 'ACT',
      urlType: ''
   },
   quotelist: {},
   'quote.quote': [
      {
         timezoneid: 'EST',
         change: '0.01',
         halted: '0',
         type: 'EQ',
         bidsize: '2900',
         fastmarket: '0',
         asksize: '300',
         close: '16.64',
         timestamp: 'May 18, 2011 3:00 PM EST',
         open: '16.64',
         productid: 'CSCO:NSDQ:EQ',
         bid: '16.63',
         exchange: 'NSDQ',
         symbol: 'CSCO',
         news: '0',
         quotetype: '2',
         percentchange: '0.0006',
         symboldesc: 'CISCO SYS INC COM',
         price: '16.65',
         utctime: '1305748800',
         volume: '92738240',
         high: '16.66',
         quotestatus: '0',
         low: '16.34',
         ask: '16.64',
         timestring2: '05/18/11 04:00 PM ET'
      },
      {
         timezoneid: 'EST',
         change: '0.04',
         halted: '0',
         type: 'EQ',
         bidsize: '91200',
         fastmarket: '0',
         asksize: '241000',
         close: '2.14',
         timestamp: 'May 18, 2011 3:00 PM EST',
         open: '2.13',
         productid: 'SIRI:NSDQ:EQ',
         bid: '2.17',
         exchange: 'NSDQ',
         symbol: 'SIRI',
         news: '0',
         quotetype: '2',
         percentchange: '0.0187',
         symboldesc: 'SIRIUS XM RADIO INC COM',
         price: '2.18',
         utctime: '1305748800',
         volume: '74540998',
         high: '2.2',
         quotestatus: '0',
         low: '2.12',
         ask: '2.18',
         timestring2: '05/18/11 04:00 PM ET'
      }
   ]
}
我想在站点上显示一些响应值。但我无法检索这些值。 有人能帮忙吗

$.ajax({ 
    type: 'GET', 
    url: quoteURL, 
    dataType: 'json', 
    timeout: 10000, 
    crossDomain: true, 
    success: function(result) {
        alert(result.descriptor[0].template);
    }
});
如果您想循环使用所有描述符:

$.each(result.descriptor, function() {
    var template = this.template;
    var componentname = this.componentname;
    // TODO: process the template and componentname
});
或:


等等。。。根据您想要显示的内容,您可以使用定义全局变量,以防将响应用于成功函数范围之外。 只用

var cachedResp;//at global scope
$.ajax({ 
    type: 'GET', 
    url: quoteURL, 
    dataType: 'json', 
    timeout: 10000, 
    crossDomain: true, 
    success: function(result) {
        cachedResp = result; //this is now available out of the function
    }
});

你是一台机器,这就是我要说的全部我想显示“quote.quote”中的值。但是我得到了错误“TypeError:Result of expression”Result.quote“[undefined]不是对象”。所以,我想知道为什么结果是这样的。quote.quote[0]。symbol没有work@Hozefa,您是否尝试了
警报(结果['quote.quote'][0].symboldesc)?是的,我试过了。我开始使用警报(结果['quote.quote'][0].symboldesc);
var cachedResp;//at global scope
$.ajax({ 
    type: 'GET', 
    url: quoteURL, 
    dataType: 'json', 
    timeout: 10000, 
    crossDomain: true, 
    success: function(result) {
        cachedResp = result; //this is now available out of the function
    }
});