JSON does not arrive complete when sending by Bundle

1

I'm trying to get the return of a push in android through the Bundle, however I'm having some problem performing bundle.getString("Message"); because it does not get all my answer that is in JSON format, it follows the format of the message: / p>

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

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

[
      {
        "Key": "type"

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

    
asked by anonymous 07.03.2016 / 15:22

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 not, this will be of help.

First of all in your Activity that will send the data you should pass the values in String or some Parcelable class , since it is not possible to transmit objects of type JSON through the Bundle.

In the Activity you are sending 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 the Activity you will receive the data:

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