Converting Message from RabbitMQ into string/json

前端 未结 2 1631
傲寒
傲寒 2021-01-12 02:44

I am currently struggling hard with a fair simple problem. I want to receive a message from RabbitMQ and have that transformed into a string (or later a json object). But al

2条回答
  •  渐次进展
    2021-01-12 03:01

    If you want to parse to a JSONObject, the best way is add the RabbitMQ message to a StringBuilder in String format. Then parse the StringBuilder into a JSONObject, by using any of the conversion utils.
    For e.g.:

    StringBuilder sb = new StringBuilder();
    sb.append(publisher.toString());
    payload = (JSONObject)jsonParser.parse(sb.toString());
    

提交回复
热议问题