2017-05-31 92 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

相關問題