【问题标题】:How to parse one response in json?如何解析json中的一个响应?
【发布时间】:2015-08-19 07:47:48
【问题描述】:

我收到了我正在对 zimbra 执行的 SearchRequest 的响应。

怎么可能会有未读邮件?

在这种情况下,u:1 表示未读,u:0 已读

这是我收到警报的响应示例

var response = result.getResponse();
alert(response.toSource());

这是警报。

({SearchResponse:{sortBy:"dateDesc", offset:0, c:[{id:"-441", u:1, n:1, f:"u", d:1439699427000, su:"Daily mail report for 2015-08-15", fr:"Grand Totals -- messages 1 received 2 delivered 0 forwarded 1 deferred (5 deferrals) 0 bounced 0 rejected (0%) 0 reject warnings 0 held 0 discarded ...", e:[{a:"admin@localhost.local", d:"admin", t:"f"}], m:[{id:"441", s:"5103", l:"300", f:"u"}], sf:"1439699427000"}, {id:"314", u:0, n:2, f:"s", d:1438663876000, su:"lokitox", fr:"lex", e:[{a:"admin@localhost.local", d:"admin", t:"f"}], m:[{id:"313", l:"300"}, {id:"312", l:"5", f:"s"}], sf:"1438663876000"}, {id:"-309", u:0, n:1, d:1438662639000, su:"Daily mail report for 2015-08-03", fr:"Grand Totals -- messages 91 received 117 delivered 0 forwarded 134 deferred (134 deferrals) 169 bounced 0 rejected (0%) 0 reject warnings 0 held 0 ...", e:[{a:"admin@localhost.local", d:"admin", t:"f"}], m:[{id:"309", s:"7232", l:"300"}], sf:"1438662639000"}], more:false, _jsns:"urn:zimbraMail"}})

我想输入一个变量,即未读电子邮件的计数。

我想象的是count(),但不知道如何在纯javascript中做到这一点。

【问题讨论】:

    标签: javascript arrays json object zimbra


    【解决方案1】:

    试试这个,这个会遍历你的对象,循环会找到所有未读键并打印所有未读键的值。

    for(var k in response){
    
        for(var r in response[k].c){
    
            console.log(response[k].c[r].u);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-20
      • 2012-03-27
      • 1970-01-01
      • 2013-09-24
      • 2015-05-25
      • 1970-01-01
      • 2019-02-16
      相关资源
      最近更新 更多