我正在实现一个带有输入的简单服务 where
{ "a": <float>, "b": <float>, "operation": <string>}
现在,我想要两个
"a": 10
和
"a": 10.0
去工作。如果我只检查浮动案例,我会得到
error: error, message: 'int' cannot be cast to 'float'
我收到请求并执行以下操作
json operationReq = check req.getJsonPayload();
float a = 0;
var intInput = <int>operationReq.a;
match intInput {
int value => a = value;
error err => a = check <float>operationReq.a;
}
上面的代码有效。但这是正确的做法,还是黑客行为?