Reputation: 320
Given the following JSON object example:
jsonObject.put("Names", jsonArray);
try{
FileWriter jsonFileWriter = new FileWriter(jsonFilePath);
jsonFileWriter.write(jsonObject.toJSONString());
jsonFileWriter.flush();
jsonFileWriter.close();
System.out.print(jsonObject);
} catch (IOException e){
e.printStackTrace();
}
I am using JAVA Server and Client that are using sockets, can I use
os.println(jsonObject);
To send it to the client, or is there another method to send the JSON object?
Upvotes: 0
Views: 3438
Reputation: 1731
You would need to call the toJSONString()
:
os.println(jsonObject.toJSONString());
Otherwise the toString()
method is called on jsonObject
.
Upvotes: 1