如何在这里将myobject转换为json?在这里,myobject的类型是<class'oci.identity.models.cardio.cardio'>

2024-09-30 16:29:32 发布

您现在位置:Python中文网/ 问答频道 /正文

此函数提供一个租约中直至其端点的所有隔间。此处myobject的类型为<;“oci.identity.MODULES.CAY.CAY”类>;如何将其转换为json?这是哪种类型的?在使用json.dumps()时,它显示类型隔间不可json序列化

'''

import oci
import hashlib

import uuid
import json

global finale_response,tenant_id,profile
profile="abc-profile"
tenant_id = "ocid1.tenancy.oc1.."
finale_response = []

config = oci.config.from_file(profile_name=profile)

def get_compartments(id):
    identity_client = oci.identity.IdentityClient(config)
    list_compartments_response = identity_client.list_compartments(compartment_id=id)
    response = list_compartments_response.data
    if response != []:
    
        child_compartment_list = []

        for i in range(len(response)):
            compartmentId = response[i].id
            myobject= response[i]

            print(type(myobject))
        
            finale_response.append({"profileName":profile,
                              "compartmentId":compartmentId,
                              "tenantId": tenant_id,
                              "comMetadata":myobject})

            child_compartment_list.append(compartmentId)

        for id in child_compartment_list:
            get_compartments(id)

    return finale_response

myList = get_compartments(tenant_id)
print(myList)
print(type(myList))

'''


Tags: importidjson类型responseprofileidentitylist