title: How can you deserialize an escaped JSON string with NSJSONSerialization?
body: <p>I have an iOS app that needs to process a response from a web service. The response is a serialized JSON string containing a serialized JSON object, looking something like this:</p>
  <pre><code>&quot;{ \&quot;name\&quot; : \&quot;Bob\&quot;, \&quot;age\&quot; : 21 }&quot;
  </code></pre>
  <p>Note that this response is a JSON <em>string</em>, not a JSON object. What I need to do is deserialize the string, so that I get this:</p>
  <pre><code>{ &quot;name&quot; : &quot;Bob&quot;, &quot;age&quot; : 21 }
  </code></pre>
  <p>And then I can use <code>+[NSJSONSerialization JSONObjectWithData:options:error:]</code> to deserialize that into an <code>NSDictionary</code>.</p>
  <p>But, how do I do that first step?  That is, how to I &quot;unescape&quot; the string so that I have a serialized JSON object?  <code>+[NSJSONSerialization JSONObjectWithData:options:error:]</code> only works if the top-level object is an array or a dictionary; it doesn't work on strings.</p>
  <p>I ended up writing <a href="https://gist.github.com/kristopherjohnson/5715018" rel="nofollow noreferrer">my own JSON string parser</a>, which I hope conforms to <a href="https://www.rfc-editor.org/rfc/rfc4627#section-2.5" rel="nofollow noreferrer">section 2.5 of RFC 4627</a>.  But I suspect I've overlooked some easy way to do this using <code>NSJSONSerialization</code> or some other available method.</p>