1
私はforループを複数のレベルで実行しています。ループの各レベルはjsonを返します.jsonは階層に配置する必要があります。私たちは、forループをもとに、ネストされた階層と、最終的なJSONを作成する必要がPython辞書を使用して入れ子になったjsonを作成しました
Traceback (most recent call last):
File "Test.py", line 80, in <module>
output[aid][bid] = bjson
TypeError: 'unicode' object does not support item assignment
以下のよう
output = {}
for a in alist:
aid, ajson = hit_api(url1)
output[aid] = ajson
for b in blist:
bid, bjson = hit_api(url2)
output[aid][bid] = bjson -- this is where we are getting error
エラーです。それはajson
ように思える
aid:ajson
|
---bid:bjson
|
--- cid:cjson
|
etc.
をアジソンの下で。 – srinath
私は答えを更新しました:) –
しかし、まだエラーが発生します。 出力[aid] = json.load(str(ajson)) ファイル "/usr/lib/python2.7/json/__init__ .py "、行286、ロード中 リターンロード(fp.read()、 )AttributeError: 'str'オブジェクトに属性 'read'がありません – srinath