Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem you're having is that Google's response uses a different encoding than the ASCII or UTF8 that you're expecting. Using the handy command line tool <code>curl</code>, it's easy to see that:</p> <pre><code>$ curl -I http://www.google.com/ig/api?weather=Paris HTTP/1.1 200 OK X-Frame-Options: SAMEORIGIN Content-Type: text/xml; charset=ISO-8859-1 ... </code></pre> <p>If you look up ISO-8859-1, you'll find that it's also known as the Latin-1 character set. One of the built-in encoding options is <code>NSISOLatin1StringEncoding</code>, so do this:</p> <pre><code>NSString *XML = [NSString stringWithContentsOfURL:URL encoding:NSISOLatin1StringEncoding error:&amp;error]; </code></pre> <p>Using the correct encoding will make it possible for NSString to figure out how to interpret the characters, and you'll get back usable data. Alternately, you may be able to modify your request to specify the character encoding that you want Google to provide. That might be preferable, so that you don't have to try to match the encoding you use to a specific request.</p> <p><strong>Edit:</strong> Up to this point, my answer focusses on just getting the response as a readable string. I see that you're real question involves parsing with NSXMLParser, though. I think you have at least two options here:</p> <ul> <li><p><strong>Modify the XML</strong> that you receive to include the character encoding. The XML that you get back is Latin-1 encoded, but the XML tag says just: <code>&lt;?xml version="1.0"?&gt;</code>. You could modify that to look like: <code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;</code>. I don't know if that would solve the problem with NSXMLParser, but it might.</p></li> <li><p>As suggested above, <strong>request the character set that you want</strong> from Google. Adding a <code>Accept-Charset</code> header to the request should do the trick, though that'll make retrieving the data a little more complicated.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload