0

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?

1 Answer 1

1

You would need to call the toJSONString():

os.println(jsonObject.toJSONString());

Otherwise the toString() method is called on jsonObject.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.