这个 NSDictionary 的设置方式有效吗?使用 XML 到 NSDictionary 插件
我正在使用此处找到的 XMLReader 插件 https://github.com/Insert- Witty-Name/XML-to-NSDictionary 将我的 XML 数据转换为 NS-Dictionary,但我对字典的设置方式感到困惑。这是我得到的:
{
response = {
"@status" = ok;
authentication = {
"@description" = "The username you provided is valid.";
"@login" = USERNAME;
"@response" = success;
"@user_id" = USERID;
};
};
}
我试图获取响应对象并说如果键等于成功则执行某些操作,但我不确定该字典是否设置正确。
I'm using the XMLReader plugin found here https://github.com/Insert-Witty-Name/XML-to-NSDictionary to convert my XML data into an NS-Dictionary, but I am confused by how the dictionary is being set up. Here is what I am given:
{
response = {
"@status" = ok;
authentication = {
"@description" = "The username you provided is valid.";
"@login" = USERNAME;
"@response" = success;
"@user_id" = USERID;
};
};
}
I am trying to take the response object and say if key is equal to success then do something, but I'm not sure if this dictionary is even set up correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管@names 作为键很奇怪,但它似乎是有效的。
您可以轻松地请求元素响应(
[ objectForKey:@"response"]
),获取[ objectForKey:@"authentication"]
,然后获取[ objectForKey :@"@response"]
检查[yourString isEqualToString:@"success"]
。编辑:添加示例
我最近注意到一些;逗号应该在哪里,但我们希望这只是一个错字或类似的东西。
如果您有疑问,您可以随时
NSLog(@"%@", [yourFirstDictionary allKeys]);
来确保这些密钥有效。为了示例起见,我们将您的第一个对象命名为
myDict
。Despite the weirdness of the @names as keys, it seems valid.
You could easily ask for your element response (
[ objectForKey:@"response"]
), get the[ objectForKey:@"authentication"]
and then[ objectForKey:@"@response"]
to check[yourString isEqualToString:@"success"]
.Edit: Adding example
I've recently noticed some ; where commas should have been, but let's hope that's just a typo or something like it.
In case you have a doubt, you can always
NSLog(@"%@", [yourFirstDictionary allKeys]);
to make sure those are valid keys.Let's call your first object
myDict
for the sake of the example.