//test.py
1 import json
2
3 data = [{'I':1,'you':2}]
4 print(type(data), data)
5 _json = json.dumps(data)
6 print(type(_json), _json)
7 print('format', json.dumps({'I':1, 'you':2}, sort_keys=True, indent=2, separators=(',',':')))
8 _data = json.loads(_json,'utf-8')
9 print(type(_data), _data)
10
11 jsonData = '{"I":1,"you":2}'
12 text = json.loads(jsonData)
13 print(type(text), text)
14
15 ustr = u'I am fool'
16 print('u', ustr)
17 str = ustr.encode()
18 print('s', str)
result:
# python test.py
(<type 'list'>, [{'I': 1, 'you': 2}])
(<type 'str'>, '[{"I": 1, "you": 2}]')
('format', '{
"I":1,
"you":2
}')
(<type 'list'>, [{u'I': 1, u'you': 2}])
(<type 'dict'>, {u'I': 1, u'you': 2})
('u', u'I am fool')
('s', 'I am fool')