回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有一个文件夹,里面有大约20000个JSON文件。我想找出每个JSON的所有唯一键,并将所有键合并。然而,我只停留在最初的一步。我能够找到单个JSON文件的密钥。</p>
<p>到目前为止,我已经编写了以下代码:</p>
<pre><code>from pprint import pprint
import json
json_data=open("/Users/akira/out/1.json")
jdata = json.load(json_data)
for key, value in jdata:
pprint("Key:")
pprint(key)
</code></pre>
<p>它给了我一个错误如下:</p>
<pre><code>Traceback (most recent call last):
File "/Users/akira/PycharmProjects/csci572/linkedbased.py", line 8, in <module>
for key, value in jdata:
ValueError: need more than 1 value to unpack
</code></pre>
<p>我的JSON是一个嵌套的JSON。请告诉我怎样才能拿到所有的钥匙。</p>
<pre><code>{
"a": "Offer",
"inLanguage": "et",
"availabl": {
"a": "Place",
"address": {
"a": "PostalAddress",
"name": "Oklahoma"
}
},
"description": "Smith and Wesson 686 357 magnum 6 inch barrel wood handle great condition shoots great.",
"priceCurrency": "USD",
"geonames_address": [
{
"a": "PopulatedPlace",
"hasIdentifier": {
"a": "Identifier",
"label": "4552707",
"hasType": "http://dig.isi.edu/gazetteer/data/SKOS/IdentifierTypes/GeonamesId"
},
"hasPreferredName": {
"a": "Name",
"label": "Tahlequah"
},
"uri": "http://dig.isi.edu/gazetteer/data/geonames/place/4552707",
"fallsWithinState1stDiv": {
"a": "State1stDiv",
"uri": "http://dig.isi.edu/gazetteer/data/geonames/place/State1stDiv/US_OK",
"hasName": {
"a": "Name",
"label": "Oklahoma"
}
},
"score": 0.5,
"fallsWithinCountry": {
"a": "Country",
"uri": "http://dig.isi.edu/gazetteer/data/geonames/place/Country/US",
"hasName": {
"a": "Name",
"label": "United States"
}
},
"fallsWithinCountyProvince2ndDiv": {
"a": "CountyProvince2ndDiv",
"uri": "http://dig.isi.edu/gazetteer/data/geonames/place/CountyProvince2ndDiv/US_OK_021"
},
"geo": {
"lat": 35.91537,
"lon": -94.96996
}
}
],
"price": 750,
"title": "For Sale: Smith &amp; Wesson 686",
"publisher": {
"a": "Organization",
"name": "armslist.com",
"uri": "http://dig.isi.edu/weapons/data/organization/armslist"
},
"uri": "http://dig.isi.edu/weapons/data/page/13AD9516F01012C5F89E8AADAE5D7E1E2BA97FF9/1433463841000/processed",
"seller": {
"a": "PersonOrOrganization",
"description": "Private Party"
} //, ...
}
</code></pre>