I created an HttpURLConnection between a server. It is shown below
public class SimpleHTTPRequest {
public static void main(String[] args) {
HttpURLConnection connection = null;
OutputStreamWriter wr = null;
BufferedReader rd = null;
StringBuilder sb = null;
String line = null;
try {
URL serverAddress = new URL("myUrl");
//set up out communications stuff
connection = null;
//Set up the initial connection
connection = (HttpURLConnection)serverAddress.openConnection();
connection.setRequestMethod("GET");
connection.connect();
//read the result from the server
rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
sb = new StringBuilder();
while ((line = rd.readLine()) != null)
{
sb.append(line + '\n');
System.out.println(sb.toString());
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally
{
//close the connection, set all objects to null
connection.disconnect();
rd = null;
sb = null;
wr = null;
connection = null;
}
}
}
After connecting to my server I get a response in this format, which is an HTML5 response.
event: data
data: {"target":1,"data": {"text":"Home","number":0,"id":02123421,"likes":[],"newPost":true,"created":1458300896392,"edited":1458300896392},"type":"create"}
But how do I parse this information for instance lets say I want the "text" home to be set to my text view how do I specifiy?