json
2018-09-17 本文已影响0人
SharlotteZZZ
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式
json.dumps: Python obj to JSON string
json.loads: coded JSON string to Python object
import json
data={'info_type': 'PING',
'log_files': 'my other log files',
'machine_name': 'machine b',
'radial_ID': 'sampleID'}
dataStr=json.dumps(data)
obj = [[1,2,3],123,123.123,'abc',{'key1':(1,2,3),'key2':(4,5,6)}]
encodedjson = json.dumps(obj)
repr(obj)
#"[[1, 2, 3], 123, 123.123, 'abc', {'key1': (1, 2, 3), 'key2': (4, 5, 6)}]"
print(encodedjson)
#[[1, 2, 3], 123, 123.123, "abc", {"key2": [4, 5, 6], "key1": [1, 2, 3]}]
You will find in the process of json encoding, list and tuple are both converted to array in JSON.