flex 提供的Amf3Input 在做数据转换时候BUG解决办法

byte[] buf = {[0xa,0xb,0x1,0x9,0x64,0x61,0x74,0x61,0xa,0x1,0x11,0x63,0x61,0x73,0x74,0x6c,0x65,0x49,0x64,0x4,0x80,0xe3,0xcb,0xb5,0xd,0x69,0x74,0x65,0x6d,0x49,0x64,0x6,0x2b,0x63,0x6f,0x6e,0x73,0x75,0x6d,0x65,0x2e,0x74,0x72,0x61,0x6e,0x73,0x61,0x63,0x74,0x69,0x6f,0x6e,0x2e,0x31,0x1f,0x74,0x72,0x61,0x6e,0x73,0x69,0x6e,0x67,0x54,0x72,0x61,0x64,0x65,0x49,0x64,0x5,0x41,0xb0,0x23,0x28,0x52,0x0,0x0,0x0,0x1,0x7,0x63,0x6d,0x64,0x6,0x25,0x74,0x72,0x61,0x64,0x65,0x2e,0x73,0x70,0x65,0x65,0x64,0x55,0x70,0x54,0x72,0x61,0x6e,0x73,0x1]};

//上面是AMF对象的数据

 

ByteArrayInputStream bi = new ByteArrayInputStream(buf);

SerializationContext ser = new SerializationContext();

Amf3Input amfin = new Amf3Input(ser);

amfin.setInputStream(bi);

Object obj = amfin.readObject();

amfin.close();

bi.close();

通过调试以上代码发现 obj 里面有个HASHMAP数据其中一个字段的数值变成了科学计数法存放

因为科学计数法 一般形式是2.12323 E8存储的,当你通过 (Integer)map.get["字段名"] 会出现double 类型找不到的异常

解决办法。是

Object data = map.get["字段名"];

data.getClass() == java.lang.Double.class 判断下类型。再做强行转换

 

 

你可能感兴趣的:(input)