简体   繁体   English

如何从角度的嵌套json数组中获取值?

[英]How to fetch value from the nested json array in angular?

I want to fetch the value from the nested json array in angular2. 我想从angular2中的嵌套json数组中获取值。 I want to fetch the client_id from the following json array: 我想从以下json数组中获取client_id

{ "resources" : [ { {“资源”:[{

 "scope" : [ "clients.read", "clients.write" ], "client_id" : "tc53EZ", "resource_ids" : [ "none" ], "authorized_grant_types" : [ "client_credentials" ], "redirect_uri" : [ "http://ant.path.wildcard/**/passback/*", "http://test1.com" ], "autoapprove" : [ "true" ], "authorities" : [ "clients.read", "clients.write" ], "token_salt" : "C7NBIz", "allowedproviders" : [ "uaa", "ldap", "my-saml-provider" ], "name" : "My Client Name", "lastModified" : 1512452520895 } ], 

"startIndex" : 1, "itemsPerPage" : 1, "totalResults" : 1, “ startIndex”:1,“ itemsPerPage”:1,“ totalResults”:1,
"schemas" : [ " http://cloudfoundry.org/schema/scim/oauth-clients-1.0 " ] } “方案”:[“ http://cloudfoundry.org/schema/scim/oauth-clients-1.0 ”]}

Can anyone help me out. 谁能帮我吗。

Thanks & Regards 感谢和问候

Shilpa Kulkarni 希尔帕·库尔卡尼(Shilpa Kulkarni)

If your data will be single resources 如果您的数据将是单一资源

    public getClientId(data) {
      let allClients: string[] = [];
      if(data && data.resources && data.resources.length > 0) {
        data.resources.forEach((d, i) => {
          allClients.push(d.client_id);
          if(data.resources.length === i + 1) {
            this.clients = allClients; // clients will be array of type number and will be declared in component
          }
        });
      } else
        return null;
    }

If you want all client_id from resources (resources will have multiple data) then let me know i will update answer. 如果您想从资源中获取所有client_id(资源将具有多个数据),请告诉我我将更新答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM