Amira Elsayed Ismail
Amira Elsayed Ismail

Reputation: 9414

Multiline edittext enter character with json android

I have the following problem and hope that anyone can help

1- I have multiline edittext allow user to enter data with keyboard enter, 2- Then when I take the value edittext.getText().toString() and make JSON object out of it, the JSON is not formated

it is like

{

  "ItemDescription": "Yyyyy
  Yyyyyy
  Yyyyyyyyy
  Yyyyyyyyyyyy
  Yyyyyyyyyyyyyy"

}

althought it should be like

{"ItemDescription": "Yyyyy\nYyyyyy\nYyyyyyyyy\nYyyyyyyyyyyy\nYyyyyyyyyyyyyy"}

can anyone help please

Upvotes: 1

Views: 351

Answers (1)

Antrromet
Antrromet

Reputation: 15424

You can use the following code.

str = str.replaceAll("(\\r|\\n|\\r\\n)+", "\\\\n");

This will replace new line character with \n string.

Upvotes: 1

Related Questions