2013-12-22 27 views
0

我有一個問題,使用Android發送Json消息與RabbitMQ。Json with RabbitMQ

我要解析的RabbitMQ對象的字符串和字節當我recive我不知道如何解析爲JSON再次得到原始消息的消息發送消息

channel.basicPublish("", Cola_RPC, props, mensaje_parseado.toString().getBytes()); //Mensaje_parseado is the Json 

我嘗試:

String stringJSON = delivery.getBody().toString(); 
JSONObject respuesta_desparseada = new JSONObject (stringJSON); 

但它不工作。

也許是一個noobie問題,但我無法達到Google的解決方案。

預先感謝您。

回答

2

您需要更改此:

String stringJSON = new String(delivery.getBody()); 
JSONObject respuesta_desparseada = new JSONObject (stringJSON); 

您在使用從ObjecttoString()方法的調用byte[]toString()

如果你想知道爲什麼,你可以運行這個命令:

String myString = "myTest"; 
System.out.println(myString); 
System.out.println(myString.getBytes()); 
System.out.println(myString.getBytes().toString()); 
System.out.println(new String(myString.getBytes())); 
+0

它的工作,非常感謝你! – user2376979