【发布时间】:2018-06-15 19:34:39
【问题描述】:
我正在考虑如何将复杂信息从 JSON API 响应传输到(几个)Python 对象。我在下面包含了(冗长的)模型响应。请注意,有些值并不总是包含在响应中,有些值是字典列表。
是否有一种“简单”的方法可以将 JSON 响应映射到 Python 对象?理想情况下,我将如何布置课程?
模型 JSON 响应:
{
"accounts" : {
"accounting_reference_date" : {
"day" : "integer",
"month" : "integer"
},
"last_accounts" : {
"made_up_to" : "date",
"period_end_on" : "date",
"period_start_on" : "date",
"type" : "string"
},
"next_accounts" : {
"due_on" : "date",
"overdue" : "boolean",
"period_end_on" : "date",
"period_start_on" : "date"
},
"next_due" : "date",
"next_made_up_to" : "date",
"overdue" : "boolean"
},
"annual_return" : {
"last_made_up_to" : "date",
"next_due" : "date",
"next_made_up_to" : "date",
"overdue" : "boolean"
},
"branch_company_details" : {
"business_activity" : "string",
"parent_company_name" : "string",
"parent_company_number" : "string"
},
"can_file" : "boolean",
"company_name" : "string",
"company_number" : "string",
"company_status" : "string",
"company_status_detail" : "string",
"confirmation_statement" : {
"last_made_up_to" : "date",
"next_due" : "date",
"next_made_up_to" : "date",
"overdue" : "boolean"
},
"date_of_cessation" : "date",
"date_of_creation" : "date",
"etag" : "string",
"external_registration_number" : "string",
"foreign_company_details" : {
"accounting_requirement" : {
"foreign_account_type" : "string",
"terms_of_account_publication" : "string"
},
"accounts" : {
"account_period_from" : {
"day" : "integer",
"month" : "integer"
},
"account_period_to" : {
"day" : "integer",
"month" : "integer"
},
"must_file_within" : {
"months" : "integer"
}
},
"business_activity" : "string",
"company_type" : "string",
"governed_by" : "string",
"is_a_credit_finance_institution" : "boolean",
"originating_registry" : {
"country" : "string",
"name" : "string"
},
"registration_number" : "string"
},
"has_been_liquidated" : "boolean",
"has_charges" : "boolean",
"has_insolvency_history" : "boolean",
"is_community_interest_company" : "boolean",
"jurisdiction" : "string",
"last_full_members_list_date" : "date",
"links" : {
"charges" : "string",
"filing_history" : "string",
"insolvency" : "string",
"officers" : "string",
"persons_with_significant_control" : "string",
"persons_with_significant_control_statements" : "string",
"registers" : "string",
"self" : "string"
},
"partial_data_available" : "string",
"previous_company_names" : [
{
"ceased_on" : "date",
"effective_from" : "date",
"name" : "string"
}
],
"registered_office_address" : {
"address_line_1" : "string",
"address_line_2" : "string",
"care_of" : "string",
"country" : "string",
"locality" : "string",
"po_box" : "string",
"postal_code" : "string",
"premises" : "string",
"region" : "string"
},
"registered_office_is_in_dispute" : "boolean",
"sic_codes" : [
"string"
],
"subtype" : "string",
"type" : "string",
"undeliverable_registered_office_address" : "boolean"
}
【问题讨论】:
标签: python json api class object