借助Android GCM,您可以使用深度JSON“数据”字段吗? [英] With Android GCM, can you use a deep JSON 'data' field?

查看:92
本文介绍了借助Android GCM,您可以使用深度JSON“数据”字段吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也就是说,您可以发送

That is, can you send

{
  "registration_ids": ["whatever", ...],
  "data": {
    "foo": {
      "bar": {
        "baz": [42]
      }
    }
  }
}

或者是GCM请求的数据成员仅限于一个关键值对的级别?我问b / c,这个限制是由Google文档[1]中的措辞提出的,它表示数据是:

or is the "data" member of the GCM request restricted to one level of key-value pairs? I ask b/c that limitation is suggested by the wording in Google's doc[1], where it says "data" is:


A JSON对象,其字段表示消息的有效内容数据的键值对。如果存在,有效载荷数据将作为应用程序数据包含在意图中,其中关键字是附加的名称。例如,data:{score:3x1}将导致一个额外的命名分数,其值为字符串3x1。键/值对的数量没有限制,尽管对消息的总大小。可选。

A JSON object whose fields represents the key-value pairs of the message's payload data. If present, the payload data it will be included in the Intent as application data, with the key being the extra's name. For instance, "data":{"score":"3x1"} would result in an intent extra named score whose value is the string 3x1 There is no limit on the number of key/value pairs, though there is a limit on the total size of the message. Optional.

[1] http://developer.android.com/guide/google/gcm/gcm.html#request

推荐答案

我自己做了一个测试并证实了我的猜想。

Just did a test myself and confirmed my conjecture.

用这个有效载荷发送一个GCM给自己:

Send a GCM to myself with this payload:

{
  "registration_ids": ["whatever", ...],
  "data": {
     "message": {
        "bar": {
           "baz": [42]
        }
     }
  }
}

我的客户收到了它并解析了'message'这个额外的意图:

And my client received it and parse the 'message' intent extra as this:

handleMessage - message={        "bar": {          "baz": [42]        }      }  

因此,您确实可以对数据键的值进行进一步的JSON解析。

So the you can indeed do further JSON parsing on the value of a data key.

这篇关于借助Android GCM,您可以使用深度JSON“数据”字段吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆