【发布时间】:2014-09-21 12:38:38
【问题描述】:
我有一个读取 JSON 对象的网络服务,它给了我 unicodeEncodeError 异常。谷歌搜索了一下,我看到了How can I convert a dict to a unicode JSON string?
(我关注了其他与 unicodeEncodeError 相关的问题,但我仍然收到 AttributeError: 'dict' object has no attribute 'content')
我做了那个特定问题中提到的事情,现在我得到 ..... is not JSON serializable
谁能告诉我现在该怎么办?
以下是我的代码:
def someMethod()
some_data = request.data
json_string1 = json.dumps(some_data) #GETTING ERROR ON THIS LINE
json_string2 = get_string(json_string1)
archive = call.send_json(json_string2)
def get_string(value):
find_unicode = re.compile('\\\\u([\da-f]{4})')
def get_parsed_unicode(x):
return chr(int(x.group(1), 16))
return find_unicode.sub(get_parsed_unicode, str(value))
感谢您的帮助!!
【问题讨论】:
-
request.data 包含什么?
print request.data和print type(request.data) -
@laffuste: 'print request.data' 返回在 Web 服务中作为字符串传递的 JSON,'print type(request.data) 返回'
'跨度>
标签: python json django serialization