Python 2.7.9 Demo - JSON的编码、解码

 

#coding=utf-8
#!/usr/bin/python
import json;

dict = {};
dict['name'] = 'nick';
dict['say'] = 'hello world...';
dict['age'] = '20';

dict_json = repr(dict);
print dict_json;

dict_json_2 = json.dumps(dict);

print dict_json_2;

 

#coding=utf-8
#!/usr/bin/python
import json;

json_value = '{"access_token":"This is access token sample.","expires_in":7200}';

decoded = json.loads(json_value);
print decoded;
print decoded['access_token'];
print decoded['expires_in'];

 

posted @ 2015-07-02 22:42  nick_huang  阅读(305)  评论(0编辑  收藏  举报