JSON does not complete when sending by Bundle

Asked

Viewed 45 times

1

I’m trying to get the return of a push on android through the Bundle, but I’m having some problem performing bundle.getString("Message"); as it does not take all my reply which is in JSON format, follows the format of the message:

 Message=[
  {
    "Key": "type",
    "Value": "0"
  },
  {
    "Key": "msg",
    "Value": "valor"
  }
]

the bundle.getString("Message"); brings me the answer only until.

[
      {
        "Key": "type"

The rest is ignored. Any idea what this problem might be?

  • There are ways you can show how you are passing this JSON to the Bundle?

  • http://gcm-alert.appspot.com/ send via this link and in the message field add the json above.

  • Okay, you made sure the message is being passed through in one piece?

1 answer

1

Are you trying to pass information from one Activity to another? If this is the case then do according to the informed, if it is not, this will serve as help.

First in your Activity that will send the data you must pass the values in String or some class Parcelable, as it is not possible to transmit JSON type objects via the Bundle.

In the Activity you will send you can do the following:

JSONObject jsonObject = new JSONObject();
try {
    jsonObject.put("type", 0);
    jsonObject.put("msg", "valor");
} catch (JSONException e) {
    e.printStackTrace();
}
String Message = jsonObject.toString();
Intent intent = (new Intent(this, SuaActivity2.class));
intent.putExtra("Message", Message);
startActivity(intent);

And in Activity you will receive the data:

String Message = bundle.getString("Message");
try {
    JSONObject jsonObject = new JSONObject(Message);
} catch (JSONException e) {
    e.printStackTrace();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.