2

を使用してマップをシリアル化しようとしていmessagpack.write(map)ます。messagepack.read(byte[])i gotを使用した逆シリアル化中MapValue。しかし、を使用して値を取得することはできませんMapValue.get(key)。以下のこの問題を見てください

  HashMap<Object,Object> map = new HashMap<Object, Object>();
  map.put(1,"ONE");
  map.put("ONE","TWO");
  MessagePack m= new MessagePack();
  byte[] b = m.write(map);
  MessagePack m1 = new MessagePack();
  MapValue value = (MapValue)m1.read(b);
  System.out.println(value);// here I am getting {1:"ONE",2:"TWO"}

 System.out.println( value.get(1)); // printing the value for key 1. I am getting null.

これについて助けてください..ありがとう。

ナウサド

4

1 に答える 1

3

Value インターフェースを使用するには、ValueFactory を使用してキーを変換する必要があります。それは本当に直感的ではありません

// instead of value.get(1) use following
System.out.println(value.get(ValueFactory.createIntegerValue(1)));

// if the key would be a String use:
System.out.println(value.get(ValueFactory.createRawValue("key")));
于 2013-10-22T15:45:46.353 に答える