2017-05-31 61 views
-1

举例来说,如果我有这样的JSON文件:是否有可能获取此类JSON元素的数据?

{ 
"update" : { 
    "[email protected]":{ 
     "1234": {"notfication": "This is testing 1","url": "http://example1.com"}, 
     "4567": {"notfication": "This is testing 3","url": "http://facebook.com"} 
        }, 
    "[email protected]":{ 
     "abcd": {"notfication": "This is testing 1","url": "http://example2.com"}, 
     "efgh": {"notfication": "This is testing 3","url": "http://facebook.com"} 
        } 
} 
} 

是否有可能要求服务器返回的文字:“[email protected]”和“[email protected]”?

谢谢

+1

是的,这是可能的 – aw04

+0

你能告诉我怎么样? – zZPrank

+0

Object.keys(obj.update)? – aw04

回答

0
var obj = { 
         "update" : { 
           "[email protected]":{ 
            "1234": {"notfication": "This is testing 1","url": "http://example1.com"}, 
            "4567": {"notfication": "This is testing 3","url": "http://facebook.com"} 
               }, 
           "[email protected]":{ 
            "abcd": {"notfication": "This is testing 1","url": "http://example2.com"}, 
            "efgh": {"notfication": "This is testing 3","url": "http://facebook.com"} 
               } 
          } 
          }; 


       var keys = Object.keys(obj.update); 
       console.log(keys[0]); 
       console.log(keys[1]); 

另见朗高的答案here

+0

明白了。谢谢! – zZPrank

相关问题