Test.Customers = [{
"CustomerPortals":[{
"filename":"chrysanthemum.jpg",
"ext":"jpg",
},{
"name":"Lighthouse.jpg",
"filename":"lighthouse.jpg",
"ext":"jpg",
},{
"filename":"lighthouse.jpg",
"ext":"jpg",
}
}]
我有這個JSON存儲在我的DOM。有時在CustomerPortals數組中會有0個項目,有時還有多個項目。但我想通過它們解析並顯示文件名。 jquery是否使它更簡單?解析通過JSON Jquery
編輯
編輯
var Test = {};
Test.Customers = [{"CustomerItems":
"Portals":
{"id":"1","customer":"1950","resident":"yes",
"CustomPortals":
[
{"id":"11","test":"4251","portalname":"tye.jpg"},
{"id":"12","test":"4251","portalname":"Lsdf.jpg"},
{"id":"13","test":"4251","portalname":"nick.jpg"}
]
}
},
{"CustomerItems":
"Portals":
{"id":"2","customer":"1952","resident":"yes",
"CustomPortals":
[
{"id":"14","test":"4252","portalname":"Chrysanthemum2.jpg"},
{"id":"15","test":"4255","portalname":"navagin.jpg"},
{"id":"16","test":"4257","portalname":"jasoria.jpg"}
]
}
},
{"CustomerItems":
"Portals":
{"id":"3","customer":"1950","resident":"yes",
"CustomPortals":
[
{"id":"17","test":"4231","portalname":"Zsryanmum1.jpg"},
{"id":"18","test":"4651","portalname":"Ltd1.jpg"},
{"id":"19","test":"4281","portalname":"ser1.jpg"}
]
}
}
]
我想要得到的portalname所有 客戶。上面不是 顯示子陣謝謝
[即不JSON,這只是一個JavaScript對象。](http://benalman.com/news/2010/03/theres-no-such-thing -as-a-json /)它已經被解析了。一旦將它們從對象中移出,您想要如何處理這些文件名? – 2011-04-19 23:31:23
我注意到你的示例代碼缺少了「CustomerPortals」。 – Anton 2011-04-19 23:43:08
我更新了我的答案,使用更新後的示例代碼顯示了新代碼。當我試圖按照原樣使用示例代碼時,我在Firebug中遇到了錯誤。我做了一個有教養的猜測,如果我錯了,讓我知道如何解決這些錯誤。 – Anton 2011-04-20 18:39:56