开发者

How can JSON with an empty key be parsed into NSDictionary?

I get a JSON response, that contains an empty key (""):

{
    "errors": {
        "": [
            "Wrong email and password combination"
        ]
    }
}

Can this JSON be prope开发者_运维知识库rly parsed into NSDictionary using JSONKit?


If it were the data portion and you were using TouchJSON, it would typically get interpreted as null and set as an NSNull object in the dictionary rather than an NSString. (you can compare to [NSNull null]).

Not sure what happens with JSONKit or whether it being a key rather than a value would make any difference to this (I would assume not, but if its interpreted as NSNull key and there are multiple null keys this would I assume create some issues).

EDIT: Jason is correct with his comment below. NSNull is only set if there is a null value on the object - an empty string is set as an empty string in the dictionary. If the key value is an empty string then the dictionary has an object with a key of @"" (and it can be retrieved thus
[myDictionary objectForKey:@""];

Note this is all in TouchJSON


Yes, why not? The key will probably be an empty string, @"". Have you tried it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜