【问题标题】:Strophe and JSON MessagesStrophe 和 JSON 消息
【发布时间】:2013-03-03 17:32:05
【问题描述】:

我无法使用 strophe 向其他 xmpp 用户发送简单的 json 消息。创建消息的命令:

var json_stringified_msg = '{"type":"ola"}';

var reply = $msg({to: this.m_user, from: this.jid_connection, type: 'chat'}).c("body").t(json_stringified_msg);

connection.send(reply.tree());

问题是在另一端客户端在聊天中收到: {"ACTION"quot;CHANGE_MODE", "MODE"quot;KEYBOARD"}

我无法从另一边逃脱,因为它是一个封闭的客户。

如何将json消息准确发送到对方?

感谢您的帮助。

最好的问候

【问题讨论】:

    标签: json escaping xmpp strophe


    【解决方案1】:

    RFC6121 规定:

    元素包含人类可读的 XML 字符数据,用于指定消息的文本内容。

    它还指出:

    元素不得包含混合内容(如 [XML] 的第 3.2.2 节中所定义)。

    我不认为您的 JSON 正在更改为字符串。

    您可以从这里阅读:http://xmpp.org/rfcs/rfc6121.html#message-syntax-body

    【讨论】:

      【解决方案2】:

      我修改了strophe.js:

      t: function (text)
      {
          //var child = Strophe.xmlTextNode(text);
          var child = Strophe.xmlGenerator().createTextNode(text);
          this.node.appendChild(child);
          return this;
      }
      

      它对我来说很好用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多