请问如何接收发出的Dictionary类型信息?

Dictionary dic = new Dictionary();
dic.Add("message", "CALL_ACCEPTED");
dic.Add("type", "0");
dic.Add("sendUser", "abc123");

        AVIMTextMessage msg = new AVIMTextMessage();
        msg.MergeCustomAttributes(dic);

        await mConversation.SendMessageAsync(msg);

这是发送信息的code,请问接收信息那边怎么能收到 Dictionary呢?然后再得出"message"

十分感谢!

对了 , 是在unity(c#)上

AVIMTextMessage 实现了 IEnumerable> 接口,所以可以像 Dictionary 一样「存取自定义属性」。
参考代码如下:

var mre = new ManualResetEvent(false);
var r0 = Utils.NewRealtime();
var c0 = await r0.CreateClientAsync("mt1_c0");
var r1 = Utils.NewRealtime();
var c1 = await r1.CreateClientAsync("mt1_c1");

c1.OnMessageReceived += (sender, e) => {
    if (e.Message is AVIMTextMessage) {
        var textMsg = e.Message as AVIMTextMessage;
        var world = textMsg["hello"] as string;
        Console.WriteLine(world);
        Assert.AreEqual(world, "world");
        mre.Set();
    }
};

var conv = await c0.CreateConversationAsync(new List<string> { "mt1_c1" });
var msg = new AVIMTextMessage("the message with custom attributes");
msg["hello"] = "world";
await conv.SendMessageAsync(msg);
mre.WaitOne();
1 人赞了这个帖子.

十分感谢您的回复!!虽然我也找到这个继承类了 blush

您好 非常感谢您回答了我的问题 另外想请问我登录leanCloud后,怎么在我还没有创建会话的情况下,接收别人给我发来的信息(对方创建会话)?

当收到消息时,会触发 OnMessageReceived 事件,从事件参数中可以拿到 AVIMMessage 对象,这个对象中包含 ConversationId(会话 Id),根据会话 Id 就可以拉取到会话对象了。

这样子。。非常感谢!此外我发现

c1.OnMessageReceived += (sender, e) => {
if (e.Message is AVIMTextMessage) {
    var textMsg = e.Message as AVIMTextMessage;
    var world = textMsg["hello"] as string;
    -------------------------------------------------
    var aaa = textMsg["abc"] as string;
    -------------------------------------------------
    Console.WriteLine(world);
    Console.WriteLine(aaa);
    Assert.AreEqual(world, "world");
    mre.Set();
}

在msg["abc"] = "";时 , 运行到var aaa 这时候就停了,也没有报错 请问是什么回事呢?

或者是var bbb = textMsg["efg"] as string; 然而efg这个key不存在的话该怎么解决呢?