Featured post
python - What can be used instead of ast module? -
in project evaluate json data extract information. code follows :
conn = httplib.httpconnection(host) conn.request("get", "/done_json.php") r = conn.getresponse() data = r.read() tmp = ast.literal_eval(data) list = [] in tmp.keys(): list.append(tmp[a])
how can change python 2.4 compatible ?
sample of 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' (...)
don't use ast.literal_eval
, it's wrong thing job anyway. use simplejson.load(r)
(or standard json module instead of simplejson in newer versions).
ast.literal_eval designed evaluate python literals. json same, not entirely (true/false/null instead of true/false/none).
- Get link
- X
- Other Apps
Comments
Post a Comment