首页 > 解决方案 > 如何使用 python 在 Rest API 中直接发布 json 数据

问题描述

我有一个 json 格式的响应数据,现在我想发布这个 json 格式。但是我有同样的问题。

{'u_correlationid_': '', 'resolved_by': '','active': 'true', 'upon_approval': 'proceed', 'skills': '', 'parent_incident': '', 'business_impact': '', 'sys_domain': {'value': 'global', 'link': ''}, 'made_sla': 'true', 'activity_due': '2019-11-07 10:09:15', 'opened_at': '2019-09-11 16:17:24'}

当我尝试直接发布 json 数据时出现错误:

"error": "Validation error - JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@37b90445; line: 1, column: 298] (through reference chain: java.util.LinkedHashMap[\"sys_domain\"])"

我想在 Python 中修复这个错误,并用我的响应格式"而不是'我的响应格式发布我的 json 数据{"u_correlationid":""},最后我还想在发布之前将一个密钥对附加到现有的。例如-

{"u_correlationid":"",
"opened_at": "2019-09-11 16:17:24","data":"big"}

标签: pythonjsonrestapipost

解决方案


推荐阅读