dct_data = json_tour_data.__dict__
tour_data = json.dumps(dct_data)如何从json中删除这些反斜杠?这是我的输出:
"{\"strFileOpenDateAjxKey\": \"2018-01-16 12:40:22.526417\",
\"strFilePassengerAjxKey\": \"Zahra Walji\", \"strFileOpenMobileAjxKey\":
\"46464664\", \"strFileOpenDepartmentAjxKey\": \"Finance department\",
\"strFileOpenAccountCodeAjxKey\": \"CARTZS\",
\"strFileOpenProfileCodeAjxKey\": \"CARTZS\",
\"strFileopenOriginalCountryIdAjxKey\": 61, \"blnBoundAjxKey\": 1,
\"strTransactionCurrencyJsKey\": \"Shillings\",
\"intCurrencyPrecisionJsKey\": 3, \"strPackageTypeJsKey\": \"PKG\",
\"strUserNameAjxKey\": \"admin\", \"strPasswordAjxKey\": \"1234\"}"发布于 2018-01-16 07:32:45
为此您可以使用replace("\'", '"')。
json = '''{\"strFileOpenDateAjxKey\": \"2018-01-16 12:40:22.526417\",
\"strFilePassengerAjxKey\": \"Zahra Walji\", \"strFileOpenMobileAjxKey\":
\"46464664\", \"strFileOpenDepartmentAjxKey\": \"Finance department\",
\"strFileOpenAccountCodeAjxKey\": \"CARTZS\",
\"strFileOpenProfileCodeAjxKey\": \"CARTZS\",
\"strFileopenOriginalCountryIdAjxKey\": 61, \"blnBoundAjxKey\": 1,
\"strTransactionCurrencyJsKey\": \"Shillings\",
\"intCurrencyPrecisionJsKey\": 3, \"strPackageTypeJsKey\": \"PKG\",
\"strUserNameAjxKey\": \"admin\", \"strPasswordAjxKey\": \"1234\"}'''
newString = json.replace("\'", '"')
print(newString)从这里检查
这是在我旁边按下run时的输出。

发布于 2019-02-18 11:22:26
答案是,你必须只玩json.dumps()和json.loads()。
以下是我的代码:-
import json
json_data = {'key1': 'first'}
json_data = json.dumps(json_data)
return {
'statusCode': 200,
'schools': json.loads(json_data)
}上述代码的输出如下:
Response:
{
"schools": {
"key1": "first"
},
"statusCode": 200
}发布于 2018-11-18 04:42:32
我建议检查您在视图中解析tour_data变量/字典的响应对象。最初我和你有同样的问题,但是我改变了一下。
最初的实现:Response(json.dumps(a_dictionary), status=status.HTTP_200_OK)
至
新实现:Response(a_dictionary, status=status.HTTP_200_OK, content_type='json')
这里的关键是: 1.摆脱json.dumps转换方法,只需通过一个普通的python字典,例如,参见a_dictionary。2.在响应对象上设置content_type='json'。
https://stackoverflow.com/questions/48275771
复制相似问题