发布到另一个 API 时更改值
Changing value when posting to anotherAPI
我正在编写一个 API 端点,它将 post 连接到外部 API,我不确定要用于我的 viewModel
的数据类型
我已经尝试了多种操作 ViewModel 和 JsonObject 的方法,但我目前没有任何进展可以显示更接近期望的结果
这是 .NET Core 2 上的 运行,web api 项目。
我创建的class来保存数据:
public class ViewModel
{
public int AccountIds { get; set; }
public string Title { get; set; }
public string Category { get; set; }
}
JSON外部API期望:
{
"AccountIDs": [4],
"Title":"value",
"Category": "value"
}
当我尝试 POST 我的 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."
]
}```
外部 API 的 AccountIDs
属性 需要一个整数数组 ("AccountIDs": [4]
)。所以声明你的模型:
public class ViewModel
{
public int[] AccountIDs { get; set; }
public string Title { get; set; }
public string Category { get; set; }
}
我正在编写一个 API 端点,它将 post 连接到外部 API,我不确定要用于我的 viewModel
的数据类型我已经尝试了多种操作 ViewModel 和 JsonObject 的方法,但我目前没有任何进展可以显示更接近期望的结果 这是 .NET Core 2 上的 运行,web api 项目。
我创建的class来保存数据:
public class ViewModel
{
public int AccountIds { get; set; }
public string Title { get; set; }
public string Category { get; set; }
}
JSON外部API期望:
{
"AccountIDs": [4],
"Title":"value",
"Category": "value"
}
当我尝试 POST 我的 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."
]
}```
外部 API 的 AccountIDs
属性 需要一个整数数组 ("AccountIDs": [4]
)。所以声明你的模型:
public class ViewModel
{
public int[] AccountIDs { get; set; }
public string Title { get; set; }
public string Category { get; set; }
}