문제

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?

도움이 되었습니까?

해결책

You would need to call the toJSONString():

os.println(jsonObject.toJSONString());

Otherwise the toString() method is called on jsonObject.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top