alockrem
alockrem

Reputation: 767

why do cocoa arrays add quotes sometimes and not others

Using the following string:

"records": [
    {
        "record_id": "REC000000000000009",
        "name": "test 1",
        "email": "[email protected]"
    },
    {
        "record_id": "REC00000000000000A",
        "name": "test race #2",
        "email": "[email protected]"
    }
]

When I run it through the following logic only the "record_id" key has quotes. Also, only the "record_id" value does not have quotes.

NSData *httpData = [results dataUsingEncoding:NSUTF8StringEncoding];

NSError* error;
NSDictionary *dict = [NSJSONSerialization
                      JSONObjectWithData:httpData
                      options:0
                      error:&error];

The result:

records: ( { email = "[email protected]"; name = "test 1"; "record_id" = REC000000000000009; }, { email = "[email protected]"; name = "test race #2"; "record_id" = REC00000000000000A; } )

Any help understanding why this is happening is appreciated.

Upvotes: 0

Views: 51

Answers (1)

user529758
user529758

Reputation:

This just happens to be how - [NSDictionary description] formats the dictionary keys (and values). (In particular, this is the legacy NextStep property list format.) This format doesn't demand that strings without punctuation be quoted.

(Of course, neither the keys or values have actual quotes in them.)

Upvotes: 3

Related Questions