NSDictionary对象中的非字符串键? [英] Non-string key in NSDictionary object?

查看:97
本文介绍了NSDictionary对象中的非字符串键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从Foundation框架中使用NSJSONSerialization解析了一些JSON数据-但是,我正在为NSDictionary组获取一个奇怪的密钥,如下所示:

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!

推荐答案

NSDictionarydescription方法(如果使用NSLog输出字典或在调试器中打印该字典,则使用该方法)将字符串用引号引起来仅当它们包含特殊字符时.

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.

此输出格式在旧版中进行了描述《属性列表编程指南》中的-样式ASCII属性列表" :

如果字符串是严格组成的,则可以省略引号 字母数字字符,不包含空格(数字为 在属性列表中作为字符串处理). ...

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). ...

请注意,通常您不能从NSLog()输出中推断出类型. 123可以是数字或字符串.但是在这种情况下,shape只能是字符串.

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.

这篇关于NSDictionary对象中的非字符串键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆