Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

java - Backward slash gets added to double quoted string when I add that string to an JSON Object

I have a JSON Object. I need to add another key-value pair to the JSON Object. The key which is going to get appended will have values with double quotes and other special characters such as :

{"cov_details":[{"issue_date":"UNIT ,NEW JERSEY","cov":"MCWG"}],"dl_number":"NYC100000784","address":" KO VIRUDHACHALAM TK","issue_date":"24-12-2010","dob":"21-03-1971","name":"VICNESWARAN S","blood_group":"","validity":{"transport":"","non-transport":"24-03-2010 to 23-03-2030"},"father/husband":"Tim"}

But whenever I try to add this string to the code either by just adding them as a string like this :

jsonObject.put("result", Modified_Result); //Newresult is the string with the above string value

Or by converting that String to an object and then appending it to the JSON Object like this :

Object Modified_Result= NewResult;// Newresult is the string with the above string value
jsonObject.put("result", Modified_Result);

I get the same output which is

{"result":"{"cov_details":[{"issue_date":"UNIT ,NEW  
 JERSEY","cov":"MCWG"}],"dl_number":"NYC100000784","address":KO VIRUDHACHALAM  
 TK","issue_date":"24-12-2010","dob":"21-03-1971","name":"VICNESWARAN  
 S","blood_group":"","validity":{"transport":"","non-transport":"24-03-2010 to 23-03- 
 2030"},"father\/husband":"Tim"}","status-code":"101","request_id":"a2642ae9-2f10-4e9a-9f7e-c3ee1a9a2dbe"}

Note the string ,"status-code":"101","request_id":"a2642ae9-2f10-4e9a-9f7e-c3ee1a9a2dbe"} is already present in the JSON Object and it remains unaffected. The problem seems to occur whenever I add a new string with double quotes. Can you tell me how can I get an output with no backward slashes before special characters ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...