-1

Can you please help me how i can convert String into json in java class. and another one more thing how json value will be store in String another string. below maintain which string i am using to convert string into json.

String str1 = {"documentType":"employment","place_address":"Yes","reportingTo":"1","bonusAmount":"3","EmployerPostalCode":"13","EmployeeCity":"17","EmployerName":"7","EmployerCity":"10","EmployerProvince":"11","natureDescription":" 6","EmployerAddress1":"8","EmployerAddress2":"9","paidMethod":"Yearly","EmployeeName":"14","EmployeeAddress2":"16","EmployerCountry":"12","timeEmployeeWorking":"4","EmployeePostalCode":"20","job_Title":"5","EmployeeAddress1":"15","EmployeeCountry":"19","EmployerPhone":"897564564","EmployeeProvince":"18","paidAmount":"2","EmployerBusinessType":"Sole Proprietorship","start_date":"2015-10-10","EmployerEmail":"abhi@gmail.com","fileUploadErrorMessage":""}

This is string where data in key value pair. please suggest how this can be convert in string i want only value in string form.

1 Answers1

0

Here's an example of JSON expressed using a Java String.

String str1 = "{\"type\":\"employment\",\"addr\":\"Yes\",\"reportingTo\":\"1\"}";

Note that the double quotes in the JSON need to be escaped in a string literal.

There are numerous Java JSON parser libraries that will convert a JSON text (like the above string) into an in-memory object. A simple one is the "org.json" library.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • I cant change String such like this String str1 = "{\"type\":\"employment\",\"address\":"Yes","reportingTo\":\"1\"}"; All project will be reflect. – Abhishek Sharma Oct 13 '15 at 13:20
  • Well the Java code in your question doesn't compile unless you do something like I have done. I don't see how you can possibly use it without changing it. But to be honest, your question makes little sense at all. Perhaps you need to rewrite it so that we can understand what you are >>really<< asking. – Stephen C Oct 14 '15 at 11:55