为了账号安全,请及时绑定邮箱和手机立即绑定

ASP.NET Web API 2 发送 Dictionary<int, decimal>

ASP.NET Web API 2 发送 Dictionary<int, decimal>

C#
函数式编程 2022-10-23 15:47:47
我在发送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%7Dhttps://localhost:4431/api/test/dictionary?test=%22test%22%3A%7B%222019%22%3A%2230.0916481889%22%7Dhttps://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:30https://localhost:4431/api/test/dictionary?test=2019https://localhost:4431/api/test/dictionary?test=2019&test=30(从如何处理数组的长镜头https://stackoverflow.com/a/11100414/3850405)
查看完整描述

1 回答

?
反对 回复 2022-10-23
  • 1 回答
  • 0 关注
  • 102 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信