I just started tinkering with java and now am trying to send a JSON object over the socket. I tried to implement Serializable but it did not work so I've put that to hold. Now I m just trying to send a JSON object in the form of a string.
JSONObject jsontype = new JSONObject;
String stringJSON = jsontype.toString();
return stringJSON;
this.clientOut = socket.getOutputStream();
this.clientOut.write((tosend+"\n").getBytes()); // had to add \n
//otherwise it doesn't work
I have tested the receiving side of it by sending a plain string with \n and it works! but if i try to send a json object it throws a nullpointerexception error. My json object is not null as I have tested it. Is there any other way to convert a json into a regular string? I am using the org.json library.