How to trim a new line character from JSON encoded string?
-
09-12-2019 - |
Question
I am developing a Android application which communicates with a PHP server via JSON.
In my application, I am encoding a key to JSON to send to server. But after encoding,when I debug the key in logcat, it showing a new line character at the end of value:
The logcat showing me something like that:
{"accessKey":"123456789\n"}
Because of this,PHP server won't accept the JSON values.
Is there any method or suggestions to remove new line character? I already have googled this, but can't find any satisfactory solution.
Solution
If you would fix this on the server with PHP you should trim your response values using trim
Now in java this method is on the String object. string.trim();
this should also strip out the \n or other trailing whitespace