I'm trying to post a large JSON string containing tweets. Some of these tweets contain double quotes and lots of special characters. Do I need to encode the JSON string? My code works if there are no special characters or double quotes in the tweets, otherwise I don't get a response.
String jsonString = "{'data': [";
for (Tweet tweet : tweets) {
jsonString +="{'text': '" + tweet.getText() + "'},";
}
jsonString += "]}";
public void analyseTweets(String jsonString){
try {
// Send data
URL url = new URL("http://twittersentiment.appspot.com/api/bulkClassifyJson");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(jsonString);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
wr.close();
rd.close();
} catch (Exception e) {
System.out.print("Error dude!: " + e);
}
}