这是我实现GCM推送通知的PHP代码,下面是我发送的数据
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array("message" => array( "id" => $id , "date" => $date , "performance" => $performance , "attendance" => $attendance ))
);
这是我从中获取值的安卓代码
Bundle extras = intent.getExtras();
String message = intent.getStringExtra("message");
这是 json 解析器类
json = new JSONObject("{message}");
stime = json.getString("performance");
name.setText(stime);
String slecturename = json.getString("attendance");
deal.setText(slecturename);
String sroom = json.getString("date");
valid.setText(sroom);
String sfaculty = json.getString("id");
address.setText(sfaculty);
在消息字段中,我得到的值为
{"id":"1","performance":"Poor","attendance":"Present","date":"2014-02-02"}
但是我无法使用确切的id解析它并获取值,我不知道我哪里做错了。任何帮助将不胜感激
试试这个
json = new JSONObject(message);
而不是
json = new JSONObject("{message}");
更改此内容
json = new JSONObject("{message}");
自
json = new JSONObject(message);
因为你有String message = intent.getStringExtra("message");
其余的解析看起来不错