【发布时间】:2019-07-23 12:54:14
【问题描述】:
我正在编写一个将发布到外部 API 的 API 端点,但我不确定要用于我的 viewModel 的数据类型
我尝试了各种操作 ViewModel 和 JsonObject 的方法,但我目前没有任何进展可以显示更接近预期的结果 这是在 .NET Core 2、web api 项目上运行的。
我为保存数据而创建的类:
public class ViewModel
{
public int AccountIds { get; set; }
public string Title { get; set; }
public string Category { get; set; }
}
外部 API 期望的 JSON:
{
"AccountIDs": [4],
"Title":"value",
"Category": "value"
}
当我尝试将其发布到我的 API 时,我收到以下错误:
"": [
"JsonToken EndArray is not valid for closing JsonType Object. Path '', line 2, position 18."
],
"AccountIDs": [
"Unexpected character encountered while parsing value: [. Path 'AccountIDs', line 2, position 16."
]
}```
【问题讨论】:
-
在 JSON 中
AccountIds是一个数组。更新视图模型public int[] AccountIds { get; set; }
标签: c# json .net-core dotnet-httpclient