我在发送Dictionary<int, decimal>
as GET URI 请求时遇到问题。我可以轻松地在 POST 请求正文中发送具有这样值的请求并使其工作:
"test": {
"2019": 30.0916481889
}
https://stackoverflow.com/a/34030142/3850405
但是,由于我没有创建或修改任何内容,因此为了清楚起见,我不想使用正确的 HTTP 方法。正如您在上面看到的,JsonFormatter它没有Dictionary从 Javascript绑定 a Array,这就是需要使用对象的原因。
这是我正在使用的方法。我试图省略[FromUri],但该值始终为空。还尝试使用Dictionary<int, int>andDictionary<string, string>来防止文化差异。
[Route("api/test/dictionary")]
[HttpGet]
public async Task<IHttpActionResult> TestDictionary([FromUri]Dictionary<int, decimal> test){
}
我尝试过的请求,所有组合都已尝试使用和不使用 URL 编码:
https://localhost:4431/api/test/dictionary?test=%7B%222019%22%3A%2230.0916481889%22%7D
https://localhost:4431/api/test/dictionary?test=%22test%22%3A%7B%222019%22%3A%2230.0916481889%22%7D
https://localhost:4431/api/test/dictionary?test= "test":{"2019":"30"}
https://localhost:4431/api/test/dictionary?test= {"2019":"30"}
https://localhost:4431/api/test/dictionary?test= {"2019":30}
https://localhost:4431/api/test/dictionary?test= {2019:30}
https://localhost:4431/api/test/dictionary?test=2019:30
https://localhost:4431/api/test/dictionary?test=2019
https://localhost:4431/api/test/dictionary?test=2019&test=30(从如何处理数组的长镜头https://stackoverflow.com/a/11100414/3850405)
慕仙森
相关分类