I am having problem when convert string to json object.
\\n
gives out Unterminated string
. If I want to use new line I use \\n character, then it occurs the error. Example String: Hello \\n this is testing message.
double quote " gives out Expected a ',' or '}
Exception. Example String : This is a "TESTING" message.
I use to escape \\ to escape those , but still facing the JSON Exception
The \\n, intended as "newline", must be encoded as \\n in json. \\" is for quoting.
You can open the python shell, write
>>> import json
>>> json.dumps('\n"')
and see the result yourself
I use the StringEscapeUtils.escapeJavaScript() function which make my life easy. http://commons.apache.org/lang/api/org/apache/commons/lang3/StringEscapeUtils.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.