获取Django对象"不是JSON可序列化的"

时间:2014-07-30 00:51:21

标签: python json django serialization

我有一个读取JSON对象的web服务,它给了我unicodeEncodeError异常。谷歌搜索了一下之后,我看到了How can I convert a dict to a unicode JSON string?

(我跟着其他与unicodeEncodeError相关的问题,但我仍然得到了AttributeError:'dict'对象没有属性'content')

我做了那个特定问题中提到的内容,现在我得到 .....不是JSON可序列化

谁能告诉我现在该怎么做?

以下是我的代码:

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))

感谢您的帮助!!

1 个答案:

答案 0 :(得分:0)

当您将对象传递给方法时,请使用foo.serealize(true)。包括JQUERY以使用它。

相关问题