Which Best way of constructing in java

Hi below are the two approaches to construction, explain me which is the best way of constructing JSON and what is the reason.

approcah 1:

String webServiceInputJSON = "{\"firstname\":\"" + user.getFirstname() + "\",\"lastname\":\"" + user.getLastname() + "\",\"email":\""+user.getEmail() + "\"}";

System.out.println(webServiceInputJSON);

approcah 2

JSONObject webServiceInputJSON= new JSONObject();

webServiceInputJSON.put("firstname",user.getFirstname());

webServiceInputJSON.put("lastname",user.getLastname());

webServiceInputJSON.put("email",user.getEmail());

System.out.println(webServiceInputJSON.toString());...

Read More »

By: StackOverFlow - 6 days ago

Related Posts