处理浮点型参数

This commit is contained in:
范大德 2023-10-12 23:23:53 +08:00
parent d9672cd75a
commit 81891e97c9

View File

@ -100,9 +100,16 @@ public class JcPrinter extends CordovaPlugin {
JSONArray methodJsonArgs = args.getJSONArray(1);
Object[] methodArgs = new Object[methodJsonArgs.length()];
for(int i=0;i<methodJsonArgs.length();i++){
Object obj = methodJsonArgs.opt(i);
Class<?> a = m.getParameterTypes()[i];
Object obj = null;
if(a == Float.class){
obj = Float.parseFloat(methodJsonArgs.optString(i));
} else if(a == Integer.class){
obj = methodJsonArgs.optInt(i);
} else{
obj = methodJsonArgs.opt(i);
}
if(obj instanceof JSONArray){
Class<?> a = m.getParameterTypes()[i].getComponentType();
Object array = Array.newInstance(a,((JSONArray) obj).length());
for(int j=0;j<((JSONArray) obj).length();j++){
Array.set(array,j,((JSONArray) obj).opt(j));