Luke Chang
Luke Chang

Reputation: 149

Non-string key in NSDictionary object?

I've parsed some JSON data using NSJSONSerialization from the Foundation framework - however, I'm getting a weird key for an NSDictionary group as follows

"stop_times" =     (
            {
        "departure_time" = "5:48a";
        "departure_timestamp" = 1355309284;
        "service_id" = 1;
        shape = "Scarborough RT To Kennedy Station";
            }

Any idea what the key "shape" might be? Is it a string? I didn't think so since it wasn't surrounded with double quotation marks. Thanks for your help in advance!

Upvotes: 1

Views: 1192

Answers (2)

Martin R
Martin R

Reputation: 539685

The description method of NSDictionary (which is used if you output a dictionary with NSLog, or print it in the debugger) encloses strings in quotation marks only if they contain special characters.

This output format is described in Old-Style ASCII Property Lists in the "Property List Programming Guide":

The quotation marks can be omitted if the string is composed strictly of alphanumeric characters and contains no white space (numbers are handled as strings in property lists). ...

Note that in general you cannot deduce the type from the NSLog() output. 123 can be a number or a string. But in this case, shape can only be a string.

Upvotes: 4

Saurabh Passolia
Saurabh Passolia

Reputation: 8109

this is not a valid JSON string.

u can check the same putting this string in any json viewer e.g. http://json.parser.online.fr/

Upvotes: -2

Related Questions