擅长:python、mysql、java
<p>返回的<code>json</code>对象无效,因为<code>json</code>应该有<code>"</code>而不是<code>'</code></p>
<p>您可以使用<code>replace()</code>将<code>'</code>替换为<code>"</code>,然后转换为<code>json</code>对象:</p>
<pre><code>import json
data = '''{'subject': 'order', 'id':20, 'info':{"result":"record","name":"orderrecords", "items":[{"name":"apple","type":"food"},{"name":"orange","type":"food"}]}}''' # there is also a missing } in the end
data = data.replace("'", '"')
data_json = json.loads(data)
res = {elt["name"] : elt["type"] for elt in data_json["info"]["items"]}
print(res)
</code></pre>
<p>输出:</p>
<pre><code>{'apple': 'food', 'orange': 'food'}
</code></pre>
<p>注:这也将替换作为数据一部分的任何单引号(如有)</p>