我想在解析這個代碼片段的JSON文件和打印source
:讀取一個JSON文件和編碼問題
{
"trailers": {
"quicktime": [],
"youtube": [
{
"source": "mmNhzU6ySL8",
"type": "Trailer",
"name": "Trailer 1",
"size": "HD"
},
{
"source": "CPTIgILtna8",
"type": "Trailer",
"name": "Trailer 2",
"size": "Standard"
}
],
"id": 27205
},
我寫了這個代碼:
for item in j:
if item['trailers']:
e = item['trailers']
for k,value in e.iteritems():
if k == "youtube":
for innerk, innerv in k.iteritems():
if innerk == "source" :
print innerv
可惜我不能解決此錯誤:
for innerk, innerv in k.iteritems():
AttributeError: 'unicode' object has no attribute 'iteritems'
您是否嘗試過Python的[JSON](http://docs.python.org/2/library/json.html)圖書館? – SethMMorton