2013-01-18 40 views
1

很多類似的問題,但我似乎可以得到最簡單的情況下工作。更多simplejson AttributeError:'unicode'對象沒有任何屬性'get'

代碼是:

retval = urllib2.Request(callstr) 
opener = urllib2.build_opener() 
f = opener.open(retval) 
json = simplejson.load(f) 
for item in json: 
    print item.get("ExtActionResponse.info") 

JSON對象似乎得到正確填充。

json 
    ExtActionRepsonse <dict ox7122345...> 
     info   u"345167273\n1234:56768" <----- This is the data I'm expecting 
     resultCode  u"0" 
     resultStr  u"Success" 
     ...etc... 

但它扼殺在獲得項目調用。

print item.get("ExtActionResponse.info") 

感謝

+0

嘗試:'import pprint' then,'pprint.pprint(json)'加載後。讓我們看看你實際上有什麼數據。我認爲問題可能是你需要做一些像'item.get('ExtActionResponse',{})。get('info')' – sberry

回答

3

.....怎麼辦?

print json['ExtActionResponse']['info'] 
+0

你的建議工作。謝謝!我跟隨的Youtube教程不正確或過時。 – 928S4

相關問題