|
| 1 | +Microsoft Windows [Version 6.1.7601] |
| 2 | +Copyright (c) 2009 Microsoft Corporation. All rights reserved. |
| 3 | + |
| 4 | +C:\Users\u8004042>python |
| 5 | +Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on wi |
| 6 | +n32 |
| 7 | +Type "help", "copyright", "credits" or "license" for more information. |
| 8 | +>>> import json |
| 9 | +>>> data = {"key":01} |
| 10 | +>>> data |
| 11 | +{'key': 1} |
| 12 | +>>> type(data) |
| 13 | +<type 'dict'> |
| 14 | +>>> json.dump(data) |
| 15 | +Traceback (most recent call last): |
| 16 | + File "<stdin>", line 1, in <module> |
| 17 | +TypeError: dump() takes at least 2 arguments (1 given) |
| 18 | +>>> json.dumps\(data) |
| 19 | + File "<stdin>", line 1 |
| 20 | + json.dumps\(data) |
| 21 | + ^ |
| 22 | +SyntaxError: unexpected character after line continuation character |
| 23 | +>>> json.dumps(data) |
| 24 | +'{"key": 1}' |
| 25 | +>>> import pickle |
| 26 | +>>> pickle.dumps(data) |
| 27 | +"(dp0\nS'key'\np1\nI1\ns." |
| 28 | +>>> str_json = json.dumps(data) |
| 29 | +>>> str_json |
| 30 | +'{"key": 1}' |
| 31 | +>>> str_json.tobytes() |
| 32 | +Traceback (most recent call last): |
| 33 | + File "<stdin>", line 1, in <module> |
| 34 | +AttributeError: 'str' object has no attribute 'tobytes' |
| 35 | +>>> data.tobytes() |
| 36 | +Traceback (most recent call last): |
| 37 | + File "<stdin>", line 1, in <module> |
| 38 | +AttributeError: 'dict' object has no attribute 'tobytes' |
| 39 | +>>> b = bytes(str_json,"unchanged") |
| 40 | +Traceback (most recent call last): |
| 41 | + File "<stdin>", line 1, in <module> |
| 42 | +TypeError: str() takes at most 1 argument (2 given) |
| 43 | +>>> bytes |
| 44 | +<type 'str'> |
| 45 | +>>> __dir(str_json) |
| 46 | +Traceback (most recent call last): |
| 47 | + File "<stdin>", line 1, in <module> |
| 48 | +NameError: name '__dir' is not defined |
| 49 | +>>> b = bytearray() |
| 50 | +>>> byte_json = b.extend(str_json) |
| 51 | +>>> byte_json |
| 52 | +>>> b.extend(str_json) |
| 53 | +>>> str_json |
| 54 | +'{"key": 1}' |
| 55 | +>>> b=str_json.encode('ascii') |
| 56 | +>>> b |
| 57 | +'{"key": 1}' |
| 58 | +>>> b = bytearray(str_json) |
| 59 | +>>> b |
| 60 | +bytearray(b'{"key": 1}') |
| 61 | +>>> print b |
| 62 | +{"key": 1} |
| 63 | +>>> print b[0] |
| 64 | +123 |
| 65 | +>>> print b[1] |
| 66 | +34 |
| 67 | +>>> b.len |
| 68 | +Traceback (most recent call last): |
| 69 | + File "<stdin>", line 1, in <module> |
| 70 | +AttributeError: 'bytearray' object has no attribute 'len' |
| 71 | +>>> len(b) |
| 72 | +10 |
| 73 | +>>> ^Z |
0 commit comments