xml轉化成json對象

要求:將下圖xml信息轉化成json對象

轉化後的結果爲:

<script type="text/javascript">
        var myObject = {
                        "section":{
                                    "title":"Book-Signing Event",
                                    "signing":[   //用數組表示
                                                      {
                                                    "author":{"title":"Mr","name":"Vikram Seth"},
                                                    "book"  :{"title":"A Suitable Day","price":"$22.95"}
                                                      },
                                                     {
                                                    "author":{"title":"Dr","name":"Oliver Sacks"},
                                                    "book"  :{"title":"The Island of Color","price":"$12.98"}                                                      
                                                     }
                                                   ]
                                          }
                                };
         alert(myObject.section.title);                                        //Book-Signing Event
         alert(myObject.section.signing[0].book.title);           //A Suitable Day
                       
    
    </script>



發佈了24 篇原創文章 · 獲贊 17 · 訪問量 36萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章