简体   繁体   English

浮动在REST-API调用中

[英]float in REST-API call

how can one send float values to a RESTful API? 如何将浮点值发送到RESTful API?

/api/set/integername/49

/api/set/charname/B

/api/set/floatname/49.33

The third one doesn't work. 第三个不起作用。

404: Not Found

Can float values be encoded somehow to make this possible or do I have to wrap it in a json object? 可以通过某种方式对浮点值进行编码以使其成为可能,还是我必须将其包装在json对象中?

I would just do something simple like convert the decimal point to an underscore :) It's less messy than URL encoding. 我只是做一些简单的事情,例如将小数点转换为下划线:)它比URL编码少混乱。

Do you have to support scientific notation (ex 1.5e+20)? 您是否需要支持科学计数法(例如1.5e + 20)? In that case you'll have to deal with + and -. 在这种情况下,您必须处理+和-。 (though - doesn't need encoding) (尽管-不需要编码)

This is a duplicate question to Passing double/float through URL to Web Api query string 这是将URL中的double / float传递给Web Api查询字符串的重复问题

The answer provided there was to add a slash to the end of the querystring. 提供的答案是在查询字符串的末尾添加一个斜杠。 I've just tested that with a blank Microsoft WebApi2 project and it works a treat. 我刚刚用一个空白的Microsoft WebApi2项目进行了测试,它可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM