Có cách nào bằng Python để serialize một cuốn từ điển đó là sử dụng một tuple như chính:json serialize một cuốn từ điển với các bộ như chìa khóa
a={(1,2):'a'}
chỉ đơn giản là sử dụng json.dumps (a), sản xuất:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/json/__init__.py", line 230, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.6/json/encoder.py", line 367, in encode
chunks = list(self.iterencode(o))
File "/usr/lib/python2.6/json/encoder.py", line 309, in _iterencode
for chunk in self._iterencode_dict(o, markers):
File "/usr/lib/python2.6/json/encoder.py", line 268, in _iterencode_dict
raise TypeError("key {0!r} is not a string".format(key))
TypeError: key (1, 2) is not a string
có thể trùng lặp của [Cách tốt nhất để mã hóa các bộ dữ liệu với json] (http://stackoverflow.com/questions/715550/best-way-to-encode-tuples-with-json) – agf