Not sure how to structure my classes with this type of response shape #542
Unanswered
va-fivenine
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Sorry I am new to this module... I am getting most of my Reponses mapped correctly but having an issue with 1 the error I am getting is
AttributeError: 'list' object has no attribute 'items'
here is the json response
[ { "ingredient": { "name": "Phenylbutazone", "drugbank_id": "DB00812" }, "cross_sensitive_entries": [ { "ingredient": { "name": "Celecoxib", "drugbank_id": "DB00482" } } ], "summary": "As a Nonsteroidal anti-inflammatory drugs (NSAIDs)...", "description": "NSAID hypersensitivity reactions ...", "incidence": "3.29%", "evidence_type": [ "nonclinical_trial", "varying_reports" ] } ]
here is how I constructed my classes:
`
@dataclass_json
@DataClass(frozen=True)
class Ingredient:
name: str
drugbank_id: str
@dataclass_json
@DataClass(frozen=True)
class CrossSensitivity:
ingredient:Ingredient
cross_sensitive_entries:Ingredient
summary: str
description: str
incidence: str
evidence_type: list[str]
@dataclass_json
@DataClass(frozen=True)
class CrossSensitivities:
ingredient: List[CrossSensitivity]
`
the issue I am having is that the top level of response doesn't have a key or name for the dictionary so not sure how to really construct my receiving class... any help with this would be wonderful...
thank
Richard
Beta Was this translation helpful? Give feedback.
All reactions