在我的項目中,我評估了一個json數據以提取信息。代碼如下:什麼可以用來代替ast模塊?
conn = httplib.HTTPConnection(host)
conn.request("GET", "/done_json.php")
r = conn.getresponse()
data = r.read()
tmp = ast.literal_eval(data)
list = []
for a in tmp.keys():
list.append(tmp[a])
我該如何改變這是Python 2.4兼容?
樣品的json的:
{'key_64': {'size3': 'CNDCRNCDF3FY09XL7UUBCBCPTYE4H7YBG1I5MILNBW172BMHVI.png', 'id': 'CNDCRNCDF3FY09XL7UUBCBCPTYE4H7YBG1I5MILNBW172BMHVI', 'size2': '', 'size1': 'http://dev.geco.com/site/2/CNDCRNCDF3FY09XL7UUBCBCPTYE4H7YBG1I5MILNBW172BMHVI.png'}, 'key_65': {'size3': 'CNDCRNEHLW2XFFCC90PDE77EEJHJF6RC3R8PEVUACB0C34H330.png', 'id': 'CNDCRNEHLW2XFFCC90PDE77EEJHJF6RC3R8PEVUACB0C34H330' (...)
問題是返回的json是一個字符串。所以運行json.load(data)給出:`AttributeError:'str'對象沒有屬性'read``。 – DevAno1 2010-12-21 15:58:25