title: How to correctly handle an Unterminated string exception?
body: <p>I'm using the <a href="http://www.json.org/java/index.html" rel="nofollow noreferrer">JSON.org java library</a> to tinker with.</p>
  
  <p>At the moment I'm encountering an error because of <code>\n</code> characters:</p>
  
  <pre><code>try{
              String s = "{\"property:\":\"line1\n,line2\"}";
              JSONObject o = new JSONObject(s);
          }catch(Exception e){
              e.printStackTrace(System.err);
          }
  </code></pre>
  
  <p>results in:</p>
  
  <pre><code>org.json.JSONException: Unterminated string at 20 [character 0 line 2]
      at org.json.JSONTokener.syntaxError(JSONTokener.java:433)
      at org.json.JSONTokener.nextString(JSONTokener.java:261)
      at org.json.JSONTokener.nextValue(JSONTokener.java:361)
      at org.json.JSONObject.&lt;init&gt;(JSONObject.java:218)
      at org.json.JSONObject.&lt;init&gt;(JSONObject.java:325)
  </code></pre>
  
  <p>After doing a quick search I found <a href="https://stackoverflow.com/questions/4253367/how-to-escape-a-json-string-containing-newline-characters-using-javascript">this answer</a>
  which points to my string having to be escaped like so:</p>
  
  <pre><code>String s = "{\"property:\":\"line1\\n,line2\"}";
  </code></pre>
  
  <p>I would no longer see the exception and could do a string replace for <code>"\n"</code> with <code>'\n'</code>, but I'm just wondering: </p>
  
  <p><strong>is the recommended way of dealing with new lines in a JSON string in java ?</strong></p>