【发布时间】:2020-03-10 05:26:26
【问题描述】:
class_object = ModelClass(title=entity_object['title'],
entities_definition_key=entity_object['entities_definition_key'],
orderId=entity_object['orderId'],uid = json.dumps( uuid.uuid4(),
cls=UUIDEncoder))
ModelClass 是 mongoengine 模型类
json_output = class_object.serializing_method()
final_list.append(json_output)
another_class_object = AnotherModelClass(workflowId=body['workflowId'],entities_list=final_list)
another_class_object.save()
save() 到 mongodb
final_dict={}
final_dict['entities_list'] = another_class_object.entities_list
return HttpResponse(json.dumps({'entity_definition_dict':entity_definition_dict}))
输出-{'uid': "\"74b1900ccfbd44234563805ac0279d\""}
【问题讨论】:
-
你为什么要多次调用
json.dumps()? -
第一个 json.dumps() 仅用于 uid,在第二个 json.dumps() 中,我正在转储具有除 uid 之外的多个值的 dict
-
多次使用
json.dumps()是导致我认为您的问题的原因。每次调用它时,都会得到一个字符串,而不是字典。所以一个字符串被传递给下一个调用,而不是你想要的字典。 -
我知道问题是 json.dumps(),但我正在寻找解决方案
-
第一次不需要序列化。
标签: python django string response mongoengine