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'];

 

你可能感兴趣的:(python)