【发布时间】:2020-07-04 23:47:05
【问题描述】:
我有一个带有更新操作的 ASP.Net Core WebApi,如下所示:
[HttpPut("{id}")]
public async Task<IActionResult> Campaigns(long id, JObject jobject)
{
}
当我从邮递员到达这个端点时的请求和响应如下:-
{
"Zone_Code": 1,
"State_Code": 24,
"City_Code": 25,
"Sales_Associate": null,
"Operation_Associate": null,
"Traveller": null,
"Target_Sector": 5,
"Campaign_DateTime": "2020-04-04T00:00:00",
"Format": 2,
"Campaign_Name": "Test",
"Data_Criteria": null,
"IsActive":"Y",
"Stage": "Initiation"
}
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "|58a198b0-4ac4ca0838cdebce.",
"errors": {
"$": [
"The JSON value could not be converted to Newtonsoft.Json.Linq.JToken. Path: $ | LineNumber: 1 | BytePositionInLine: 8."
]
}}
【问题讨论】:
-
为什么你使用
JObject作为动作的参数?你可以使用一个简单的对象 -
我的处理程序代码使用反射来设置属性值
-
我在您的问题中没有看到处理程序,我尝试了一个简单的测试,
JObject给了我同样的错误,并且使用 simple object 我是调用 Action.
标签: json.net