jsonObject.addProperty Method is adding unnecessary Quotation Marks and Slashes to it's value
From your comments and logcat info, the actual value getting from SharedPreferences
is "/SUeSjUf0A0aLFr+wVIZbw==y9iWl1SSrUe9zRQppENMNA"
(having quotation marks), not /SUeSjUf0A0aLFr+wVIZbw==y9iWl1SSrUe9zRQppENMNA
. That's why you got jsonToSubmit : {"token":"\"/SUeSjUf0A0aLFr+wVIZbw==y9iWl1SSrUe9zRQppENMNA\""}
UPDATE:
For your temporary solution:
jsonToSubmit.addProperty("token",currentTokenNo.substring(1,currentTokenNo.length()-1));
I prefer the following way:
jsonToSubmit.addProperty("token", currentTokenNo.replaceAll("\"",""));
If you also want to remove slashes, then use:
jsonToSubmit.addProperty("token", currentTokenNo.replaceAll("\"","").replaceAll("/",""));
Hope it helps!
Whatever you get in your logcat is correct.
Below are few points and reason why that happen so:
1) Unnecessary slashes added to your token. Why? Because your token contains back slash (\) that is an escaping character. So to it will be written as double slash (\\) instead of single slash (\).
2) Unnecessary quotation mark added to your token. Why? Again, your token is an String object and starts with a quotation ("). So it will be written as \".
So the overall you token changes from "/SUeSjUf0A0aLFr+wVIZbw==\nLmmWtgHZ90yH0NBoATYB/A"
to "\"/SUeSjUf0A0aLFr+wVIZbw==\\nLmmWtgHZ90yH0NBoATYB/A\""
. But you need not to worry as whenever you will get your token data from JsonObject
, you will always get the same token which you were added.
For more info about escape character, see here: https://docs.oracle.com/javase/tutorial/java/data/characters.html