gpt4 book ai didi

javascript - jQuery/Javascript 从对象中提取信息

转载 作者:行者123 更新时间:2023-11-28 16:40:02 26 4
gpt4 key购买 nike

我正在尝试使用以下代码从 Ajax 调用返回的一些 json 创建客户端名称列表。

数据如下:

{"status":1,"data":{"clients":[{"ClientID":"1","AccountID":"1","ClientName":"Access Loan Mitigation","Active":"1 "},{"ClientID":"2","AccountID":"1","ClientName":"Big Time Business","Active":"1"},{"ClientID":"3","AccountID ":"1","ClientName":"Bill Releford","Active":"1"},{"ClientID":"4","AccountID":"1","ClientName":"Bonnie Silverman", "Active":"1"},{"ClientID":"5","AccountID":"1","ClientName":"Dear Holdings","Active":"1"},{"ClientID":"6","AccountID":"1","ClientName":"Calm Dental","Active":"1"},{"ClientID":"7","AccountID":"1","ClientName": "Eva Field","Active":"1"},{"ClientID":"8","AccountID":"1","ClientName":"First Independent Pictures","Active":"1"}, {"ClientID":"9","AccountID":"1","ClientName":"Gallery 825","Active":"1"},{"ClientID":"10","AccountID":"1 ","ClientName":"Greenway Arts Alliance","Active":"1"},{"ClientID":"11","AccountID":"1","ClientName":"International Strategy Group","Active ":"1"},{"ClientID":"12","AccountID":"1","ClientName":"Ramtin","Active":"1"},{"ClientID":"13", “帐户ID” :"1","ClientName":"Spabro","Active":"1"},{"ClientID":"14","AccountID":"1","ClientName":"LMGA","Active":"1"},{"ClientID":"15","AccountID":"1","ClientName":"Main Street Business Association","Active":"1"},{"ClientID":"16 ","AccountID":"1","ClientName":"Rabbit Animation","Active":"1"},{"ClientID":"17","AccountID":"1","ClientName":"房间和花园","Active":"1"},{"ClientID":"18","AccountID":"1","ClientName":"Summertime","Active":"1"},{"ClientID":"19","AccountID":"1","ClientName":"Sue Shellock","Active":"1"},{"ClientID":"20","AccountID":"1", "ClientName":"Susan Gates","Active":"1"},{"ClientID":"21","AccountID":"1","ClientName":"The Park Entertainment","Active":"1"},{"ClientID":"22","AccountID":"1","ClientName":"Unified Dispatch","Active":"1"},{"ClientID":"23","AccountID ":"1","ClientName":"Westside Media Group","Active":"1"},{"ClientID":"24","AccountID":"1","ClientName":"YHD", "Active":"1"},{"ClientID":"25","AccountID":"1","ClientName":"Discoverfire, Inc.","Active":"1"}]}}

代码是这样的:

        for (var Client in o.data.clients) {
$('#list_container').append("<div>"+Client.ClientName+"</div>");
}

不太好用,我尝试了几种不同的方法来访问 ClientName 属性。 Javascript 不是我最擅长的语言,而从对象中获取数据只会让我感到沮丧 - 习惯于 PHP 对象和数组。

我敢肯定这很简单——有人可以显示正确的语法吗?

谢谢!

最佳答案

Clients 是一个数组,所以最好使用 jQuery 的 each在上面:

$.each( o.data,clients, function(idx, client) {
// use client.ClientName here
});

关于javascript - jQuery/Javascript 从对象中提取信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1364695/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com