0

我正在尝试使jvectormap中的“转换器”脚本正常工作,但出现以下错误,

ultural$ python ../../../../jvectormap/converter/converter.py --width 1000 --country_name_index 1 --country_code_index 30 --where "'ISO = DEU'" --projection aea --name datag_germany --language en_US ne_10m_admin_1_states_provinces_shp.shp here.js
ERROR 1: Not enough tokens to complete expression.
Traceback (most recent call last):
  File "../../../../jvectormap/converter/converter.py", line 294, in <module>
    converter.convert(args['output_file'])
  File "../../../../jvectormap/converter/converter.py", line 182, in convert
    open(outputFile, 'w').write( self.map.getJSCode() )
  File "../../../../jvectormap/converter/converter.py", line 30, in getJSCode
    return "jQuery.fn.vectorMap('addMap', '"+self.name+"_"+self.projection['type']+"_"+self.language+"',"+json.dumps(map)+');'
  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 275, in _iterencode_dict
    for chunk in self._iterencode(value, markers):
  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 273, in _iterencode_dict
    yield encoder(key)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe1 in position 4: unexpected end of data

我想知道,我应该如何处理 json.dumps 和编码 - 这似乎是这种情况下的主要问题。我正在使用 python 2.6;

4

1 回答 1

2

我通过将包含“异国情调”字符的字符串转换为 utf8 来解决 json 转储和编码的类似问题,从而处理 unicode 对象。这对我有用: .decode('utf8')

这应该有帮助: http ://www.joelonsoftware.com/articles/Unicode.html

于 2013-09-12T18:47:49.433 回答