Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending json with enter key to php web service

Tags:

json

php

I am working on PHP web service for android app.

Here I am sending json :

{"company":"wipro","user_id":19,"title":"title_update","from_date":"01-02-2014","to_date":"11-02-2014","additional_notes":"worked with 3 reputed firms"}

this is a valid json but requirement is that user can press 'Enter key' in additional_notes parameter which invalidates the json. Is there any solution possible for such problem? If this is impossible to send json with enter key then is that possible with Xml .

like image 602
Always_a_learner Avatar asked Sep 05 '25 01:09

Always_a_learner


2 Answers

As long as I understood your problem, you want to send the additional_notes key with value containing new-line character ('\n').

For example

{"company":"wipro","user_id":19,"title":"title_update","from_date":"01-02-2014","to_date":"11-02-2014","additional_notes":"worked with 3 reputed firms \n currently working with abc"}

the line currently working with abc was the text on the new-line.

If you are using text-area for additional_notes then it will automatically add '\n' character for new line. Adding new-line character ('\n') will not invalidate the json. What invalidates the json is when you break the value of additional_notes key to the next line in your script code.

like image 67
Vivek Avatar answered Sep 07 '25 14:09

Vivek


You can make an list/array of single text lines. Parse your multi line text before sending into single line strings and on your server you need to put them together again. Your json should then look something like this:

{"multi_line_text":["line one","line two","line three"]}

It is not the best solution but it should work

like image 23
sonallux Avatar answered Sep 07 '25 13:09

sonallux