json

作者: SharlotteZZZ | 来源:发表于2018-09-17 20:10 被阅读0次

    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.

    相关文章

      网友评论

          本文标题:json

          本文链接:https://www.haomeiwen.com/subject/xbtmgftx.html