Message229830
When running the following:
>> json.dump(['name': "港区"], myfile.json, indent=4, separators=(',', ': '), ensure_ascii=False)
the function escapes the unicode, even though I have explicitly asked to not force to ascii:
\u6E2F\u533A
By changing "__init__.py" such that the fp.write call encodes the text as utf-8, the output json file displays the human-readable text required (see below).
OLD (starting line 167):
if (not skipkeys and ensure_ascii and
check_circular and allow_nan and
cls is None and indent is None and separators is None and
encoding == 'utf-8' and default is None and not kw):
iterable = _default_encoder.iterencode(obj)
else:
if cls is None:
cls = JSONEncoder
iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
check_circular=check_circular, allow_nan=allow_nan, indent=indent,
separators=separators, encoding=encoding,
default=default, **kw).iterencode(obj)
for chunk in iterable:
fp.write(chunk)
NEW:
if (not skipkeys and ensure_ascii and
check_circular and allow_nan and
cls is None and indent is None and separators is None and
encoding == 'utf-8' and default is None and not kw):
iterable = _default_encoder.iterencode(obj)
for chunk in iterable:
fp.write(chunk)
else:
if cls is None:
cls = JSONEncoder
iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
check_circular=check_circular, allow_nan=allow_nan, indent=indent,
separators=separators, encoding=encoding,
default=default, **kw).iterencode(obj)
for chunk in iterable:
fp.write(chunk.encode('utf-8')) |
|
Date |
User |
Action |
Args |
2014-10-22 18:55:23 | Michael.Kuss | set | recipients:
+ Michael.Kuss, vstinner, ezio.melotti |
2014-10-22 18:55:23 | Michael.Kuss | set | messageid: <1414004123.6.0.971106689488.issue22701@psf.upfronthosting.co.za> |
2014-10-22 18:55:23 | Michael.Kuss | link | issue22701 messages |
2014-10-22 18:55:23 | Michael.Kuss | create | |
|