我从mongoDB数据库中获取结果,并尝试通过curl将它们作为JSON对象发送:

custos = customerDB.CustomerModel.find()

jsonCusto = []
for doc in custos:
temp = json.dumps(doc, default=json_util.default)
jsonCusto.append(temp)


我在发送并得到之前打印此:

'{"firstName": "Joshu", "lastName": "Wak", "creation": {"$date": 1414531609314}, "Cust_ID": 101, "streetNo": "3231", "_id": {"$oid": "54500a19d0f6120a0021c879"}, "email": "[email protected]", "streetName": "washingoton"}'


但是在卷曲屏幕上我得到:

"{\"firstName\": \"Joshu\", \"lastName\": \"Wak\", \"creation\": {\"$date\": 1414531609314}, \"Cust_ID\": 101, \"streetNo\": \"3231\", \"_id\": {\"$oid\": \"54500a19d0f6120a0021c879\"}, \"email\": \"[email protected]\", \"streetName\": \"washingoton\"}


我尝试了大约10种组合,但无法正确解决。我将不胜感激任何帮助。

谢谢!

最佳答案

几乎可以肯定,您对JSON进行了双重编码。只需在循环中删除json.dumps并仅在末尾使用即可:

custos = customerDB.CustomerModel.find()
jsonCusto = list(custos)
jsonText = json.dumps(jsonCusto, default=json_util.default)

10-04 19:24