擅长:python、mysql、java
<p>如果您使用的是python 3.6+,那么最简单的方法可能是使用<a href="https://github.com/lovasoa/marshmallow_dataclass" rel="nofollow noreferrer">marshmallow-dataclass</a>:</p>
<pre class="lang-py prettyprint-override"><code>from marshmallow_dataclass import dataclass
from typing import List
@dataclass
class Character:
id : int
name : str
rating : str
@dataclass
class Person:
id : int
name : str
phone : str
characteristics : List[Character]
my_person, _ = Person.Schema().loads(json_str)
</code></pre>