title: propertyListWithData: curly braces causing error in "old style" plist
body: <p>So I recently added some client-side IAP receipt validation, using Apple's widely-used <a href="https://developer.apple.com/library/ios/releasenotes/StoreKit/IAP_ReceiptValidation/" rel="nofollow">sample code</a>.</p>
  
  <p>The sample is mostly about sending receipt data to Apple's server, essentially asking if it's a real receipt or not.  But it also includes some simple, locally-performed validation.  Part of that is getting the transaction's "purchase-info", a 64-bit encoded property list, describing the purchase.</p>
  
  <p>That property list looks like this:</p>
  
  <pre><code>{
      "original-purchase-date-pst" = "2013-10-25 10:04:44 America/Los_Angeles";
      "unique-identifier" = "15546137c0c5c74672ce8b71223ad173fc2b2ac2";
      "original-transaction-id" = "1000000055641224";
      "bvrs" = "1.7";
      "transaction-id" = "100000008886513";
      "quantity" = "1";
      "original-purchase-date-ms" = "1382720684000";
      "unique-vendor-identifier" = "73F61531-4415-451B-A144-65165012BC51";
      "product-id" = "com.fakeco.FakeGame.GoldCookieBundle_1";
      "item-id" = "555555555";
      "bid" = "com.fakeco.FakeGame";
      "purchase-date-ms" = "1382720684000";
      "purchase-date" = "2013-10-25 17:04:44 Etc/GMT";
      "purchase-date-pst" = "2013-10-25 10:04:44 America/Los_Angeles";
      "original-purchase-date" = "2013-10-25 17:04:44 Etc/GMT";
  }
  </code></pre>
  
  <p>Apple's code uses NSPropertyListSerialization's propertyListWithData: method to create a dictionary from this plist.  But this function returns an error for me:</p>
  
  <pre><code>kCFPropertyListOldStyleParsingError
  Unexpected character { at line 1
  </code></pre>
  
  <p>So, after poking around Apple's docs a bit, I've learned that this ASCII key-value list is the <a href="https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/PropertyLists/OldStylePlists/OldStylePLists.html" rel="nofollow">"old style"</a> representation of plists.</p>
  
  <p>Depending on the format, the plist can represent an NSString, an NSArray, NSData, or and NSDictionary.  And the NSDicitonary, it says, "is enclosed in curly braces".  But the error I got complained that my opening curly brace was "unexpected".</p>
  
  <p>So, as a test, I added some code to remove the braces before calling the propertyListWithData: method.</p>
  
  <pre><code>decodedPurchaseInfo = [decodedPurchaseInfo stringByReplacingOccurrencesOfString:@"{" withString:@""];
  decodedPurchaseInfo = [decodedPurchaseInfo stringByReplacingOccurrencesOfString:@"}" withString:@""];
  </code></pre>
  
  <p>Then it worked!  The propertyListWithData: method properly returned an NSDictionary with the expected key-value pairs.</p>
  
  <p>Does anyone have some insight that might help me out?  I find it hard to believe that I'm the only one running into this... I mean, others must use this sample code, right?</p>
  
  <p>But what I definitely <strong>don't</strong> want to do is remove the braces and call it "fixed".<br>
  <em>"If you don't know why it's fixed, it's not fixed."</em>  </p>