title: From JavaScript to Objective-C with JSON
body: <p>I have no idea how to properly 'return' this JSON object (in JavaScript):</p>
  
  <pre><code>function callback() {   
                  var points = '{\"points\": [';
                  var params = polyline.getLatLngs();
  
                  var i;
                  for (i = 0; i &lt; points.length; i++) {
                      params = params.concat('{\"latitude\": ', points[i].lat, ', \"longitude\": ', points[i].lng, '}');
                      if (i &lt; points.length - 1) {
                          params = params.concat(', ');
                      }
                  }
                  params = params.concat('] }');
  
                  return JSON.parse(params);
              }
  </code></pre>
  
  <p>I want to catch it with something like (Objective-C): </p>
  
  <pre><code>NSString *s = [self.webView stringByEvaluatingJavaScriptFromString:@"callback();"];
  </code></pre>
  
  <p>Obviously this results in a NSString, what I really want is NSData to do this (Objective-C):</p>
  
  <pre><code>NSData *data = [s dataUsingEncoding:NSUTF8StringEncoding];
  NSDictionary *response = [NSJSONSerialization JSONObjectWithData:data options:NSJSONWritingPrettyPrinted error:&amp;error];
  </code></pre>
  
  <p>So, how to properly return the JSON?</p>