rest 接口发文本消息 TextMessageBody 对象 填充msg参数,接口返回msg must be JSONObject
String targets[] = { "test"};
JSONObject j = new JSONObject();
j.put("type", "txt");
j.put("msg", "hello");
BodyWrapper messagetxt = new TextMessageBody("users", targets, "rest", null, j.toJSONString());
System.out.println(messagetxt.getBody());
ResponseWrapper r = (ResponseWrapper) message.sendMessage(messagetxt);
System.out.println("result:" + r.getResponseBody() + "__" + r.getMessages());
如上边代码,创建messbodyde 的时候msg参数已经是jsonobject,服务器返回信息还是400,
result:{"error":"illegal_argument","timestamp":1473389121249,"duration":0,"exception":"java.lang.IllegalArgumentException","error_description":"msg must be JSONObject"}__[]
这个TextMessageBody 这样写有问题吗?
JSONObject j = new JSONObject();
j.put("type", "txt");
j.put("msg", "hello");
BodyWrapper messagetxt = new TextMessageBody("users", targets, "rest", null, j.toJSONString());
System.out.println(messagetxt.getBody());
ResponseWrapper r = (ResponseWrapper) message.sendMessage(messagetxt);
System.out.println("result:" + r.getResponseBody() + "__" + r.getMessages());
如上边代码,创建messbodyde 的时候msg参数已经是jsonobject,服务器返回信息还是400,
result:{"error":"illegal_argument","timestamp":1473389121249,"duration":0,"exception":"java.lang.IllegalArgumentException","error_description":"msg must be JSONObject"}__[]
这个TextMessageBody 这样写有问题吗?
没有找到相关结果
已邀请:
1 个回复
小新没有蜡笔
public ContainerNode<?> getBody() {
if (!isInit()) {
// this.getMsgBody().put("type", MsgType.TEXT);
// this.getMsgBody().put("msg", msg);
ObjectNode jsonNode = JsonNodeFactory.instance.objectNode();
jsonNode.put("type", MsgType.TEXT);
jsonNode.put("msg", msg);
this.getMsgBody().put("msg", jsonNode);
this.setInit(true);
}
return this.getMsgBody();
}
更改了下getbody方法。这样就可以了。