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.

Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top