Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, your string <code>json</code> does not contain the quotation characters you think it does. You have to "escape" a quote in a string with a backslash for it to not terminate the string. Your line:</p> <pre><code>NSString *json = @"{nid:"",vocab:"",inturl:testoverview, mail:chh@fbr.dk, md5pw:4d57e7ef1b7c3f431aca424764e9d786}"; </code></pre> <p>is being parsed like this:</p> <pre><code>NSString *json = @"{nid:" ",vocab:" ",inturl:testoverview, mail:chh@fbr.dk, md5pw:4d57e7ef1b7c3f431aca424764e9d786}"; </code></pre> <p>That is, it's three quoted strings in sequence. The compiler concatenates adjacent string literals. So, the effect is this:</p> <pre><code>NSString *json = @"{nid:,vocab:,inturl:testoverview, mail:chh@fbr.dk, md5pw:4d57e7ef1b7c3f431aca424764e9d786}"; </code></pre> <p>with no embedded quote characters.</p> <p>What you wanted to write was:</p> <pre><code>NSString *json = @"{nid:\"\",vocab:\"\",inturl:testoverview, mail:chh@fbr.dk, md5pw:4d57e7ef1b7c3f431aca424764e9d786}"; </code></pre> <p>Can you show the output of:</p> <pre><code>NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:NSJSONWritingPrettyPrinted error:&amp;error]; </code></pre> <p>I don't see where you would get an "=" character.</p> <hr> <p>Update:</p> <p>This code (modified from your question):</p> <pre><code>NSString *nid = @""; NSString *vocab = @""; NSString *inturl = @"testoverview"; NSString *mail = @"chh@fbr.dk"; NSString *md5pw = @"4d57e7ef1b7c3f431aca424764e9d786"; NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjectsAndKeys: nid, @"nid", vocab, @"vocab", inturl, @"inturl", mail, @"mail", md5pw, @"md5pw",nil]; NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:NSJSONWritingPrettyPrinted error:&amp;error]; NSString *resultAsString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; NSLog(@"jsonData as string:\n%@", resultAsString); </code></pre> <p>gives this output:</p> <pre><code>jsonData as string: { "md5pw" : "4d57e7ef1b7c3f431aca424764e9d786", "nid" : "", "inturl" : "testoverview", "mail" : "chh@fbr.dk", "vocab" : "" } </code></pre> <p>if you use <code>0</code> instead of <code>NSJSONWritingPrettyPrinted</code>, it gives:</p> <pre><code>jsonData as string: {"md5pw":"4d57e7ef1b7c3f431aca424764e9d786","nid":"","inturl":"testoverview","mail":"chh@fbr.dk","vocab":""} </code></pre>
 

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