javascript - 存储使用javascript返回的json数据

标签 javascript jquery

我通过 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
});

或者:

alert(result['invest.mostactive'].MoverExchange);

等等...取决于您想要显示的内容

关于javascript - 存储使用javascript返回的json数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6063453/

相关文章:

javascript - 当 ES6 中存在结构相似性时,减少分配对象属性的冗余

jquery - 如何将 jQuery 插件作为方法调用?

c# - 如何从客户端设置 HTMLEditorExtender HTML

jquery - 在旧评论加载到 jquery 上方后,将固定评论重新定位在顶部

javascript - jquery 画廊不会加载灯箱

javascript - AJAX/APACHE/PHP/HTACCESS 配置

javascript - 使用 cheerio 解析 Node JS 上的代码

javascript - 如何创建整个 <li> 可点击,然后在鼠标悬停时在顶部显示框?

Javascript 附加新的 onClick 项目格式错误

javascript - 如何将 HTML 附加到 div,同时仍然允许监听器工作?