我有以下的JSON詞典:AttributeError的:「統一」對象有沒有屬性「值」當解析JSON字典值
{
u'period': 16, u'formationName': u'442', u'formationId': 2,
u'formationSlots': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 0, 0, 0, 0, 0, 0],
u'jerseyNumbers': [1, 20, 3, 15, 17, 5, 19, 6, 18, 25, 10, 2, 4, 12, 16, 22, 24,
34],
u'playerIds': [23122, 38772, 24148, 39935, 29798, 75177, 3860, 8505,
26013, 3807, 34693, 18181, 4145, 23446, 8327, 107395, 29762, 254558],
u'captainPlayerId': 29798,
u'startMinuteExpanded': 0,
u'endMinuteExpanded': 82,
u'formationPositions': [{u'horizontal': 5.0, u'vertical': 0.0},
{u'horizontal': 1.0, u'vertical': 2.5}, {u'horizontal': 9.0, u'vertical': 2.5},
{u'horizontal':3.5, u'vertical': 6.0}, {u'horizontal': 3.5, u'vertical': 2.5},
{u'horizontal': 6.5, u'vertical': 2.5}, {u'horizontal': 1.0, u'vertical': 6.0},
{u'horizontal': 6.5, u'vertical': 6.0}, {u'horizontal': 6.5, u'vertical': 9.0},
{u'horizontal': 3.5, u'vertical': 9.0}, {u'horizontal': 9.0, u'vertical': 6.0}]
}
正如你可以看到一些字典值都包含在列表內。我想以編程方式獲得像這樣從這個對象中的所有值:
for myvalue in myjsonobject:
print mydict
for mysubvalue in myvalue:
print mysubvalue
此打印字典鍵:
period
formationName
formationId
formationSlots
jerseyNumbers
playerIds
captainPlayerId
startMinuteExpanded
endMinuteExpanded
formationPositions
當什麼其實我要的是價值。我曾嘗試與打印mysubvalue.values()
更換聯機打印mysubvalue
,然而這將導致以下錯誤:
Traceback (most recent call last):
File "C:\Python27\counter.py", line 78, in <module>
print mysubdict.values()
AttributeError: 'unicode' object has no attribute 'values'
我正在一個受過教育的猜測在這裏,我不需要用json.loads(mysubdict)
讓我訪問.values()
功能。如果是這樣,我不知道爲什麼我得到這個錯誤。
任何人都可以協助嗎?
感謝
您好。你能否詳細介紹一下你在想什麼? – gdogg371