复杂的 NSDictionary。获取键的对象并将它们排序为 NSArray 或单独的变量?
我有一个从 XML 转换而来的 NSDictionary,这让我很困惑。如果您能看一下并让我知道获取键 class_id 的对象的最佳方法,我将非常感激。
{
response= {
"@status" = ok;
rosters = {
"@page" = 1;
"@page_count" = 1;
"@records_per_page" = 50;
"@total_record_count" = 8;
roster = (
{
"@class_id" = 0001;
"@role" = 0;
"@user_id" = 12345;
class= {
"@active" = false;
"@name" = NAME;
}
}
{
"@class_id" = 0002;
"@role" = 0;
"@user_id" = 12345;
}
{
"@class_id" = 0003;
"@role" = 0;
"@user_id" = 12345;
}
);
}
}
}
我想要做的就是为各个 class_id 设置变量,或者将所有 class_id 放入 NSArray 中。我一直在阅读苹果文档,并尝试了我能想到的所有方法,但它要么因 nsException 崩溃,要么不返回任何数据。非常感谢您的帮助。
好吧,让我们备份一下。看来我用来将其转换为 NSDictionary 的 XMLReader 插件使这比实际需要的更加复杂。这是原始的 XML 数据。
<response status="ok">
<rosters page_count="1" page="1" records_per_page="50" total_record_count="7">
<roster class_id="0001" role="S" user_id="91563" roster_id="ID"/>
<roster class_id="0002" role="S" user_id="91563" roster_id="ID"/>
<roster class_id="0003" role="S" user_id="91563" roster_id="ID"/>
<roster class_id="0004" role="S" user_id="91563" roster_id="ID"/>
<roster class_id="0005" role="S" user_id="91563" roster_id="ID"/>
<roster class_id="0006" role="S" user_id="91563" roster_id="ID"/>
<roster class_id="0007" role="S" user_id="91563" roster_id="ID"/>
</rosters>
</response>
谁能建议一种简单的方法来获取 class_id 值?转换为 NSDictionary 是一种合理的方法吗?我只需要数据作为单独的变量或 NSArray。
I have an NSDictionary that was converted from XML that is really confusing me. If you could take a look and let me know the best method of getting the objects for the key class_id, I would really appreciate it.
{
response= {
"@status" = ok;
rosters = {
"@page" = 1;
"@page_count" = 1;
"@records_per_page" = 50;
"@total_record_count" = 8;
roster = (
{
"@class_id" = 0001;
"@role" = 0;
"@user_id" = 12345;
class= {
"@active" = false;
"@name" = NAME;
}
}
{
"@class_id" = 0002;
"@role" = 0;
"@user_id" = 12345;
}
{
"@class_id" = 0003;
"@role" = 0;
"@user_id" = 12345;
}
);
}
}
}
All I am wanting to do is either set up variables for the individual class_id's or put all of the class_id's in an NSArray. I've been reading the apple documentation and have tried every method I can think of, but it either crashes with nsexception or returns no data. Thanks so much for your help.
Ok let's just backup a minute. It would appear that the XMLReader plugin that I used to convert this to an NSDictionary is making this far more complicated than it needs to be. Here is the original XML data.
<response status="ok">
<rosters page_count="1" page="1" records_per_page="50" total_record_count="7">
<roster class_id="0001" role="S" user_id="91563" roster_id="ID"/>
<roster class_id="0002" role="S" user_id="91563" roster_id="ID"/>
<roster class_id="0003" role="S" user_id="91563" roster_id="ID"/>
<roster class_id="0004" role="S" user_id="91563" roster_id="ID"/>
<roster class_id="0005" role="S" user_id="91563" roster_id="ID"/>
<roster class_id="0006" role="S" user_id="91563" roster_id="ID"/>
<roster class_id="0007" role="S" user_id="91563" roster_id="ID"/>
</rosters>
</response>
Can anyone suggest a simple way to just grab the class_id values? Is converting to NSDictionary a reasonable way to do it? I just need the data as separate variables or an NSArray.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要担心“最好的方法”。只需使用一种不会在以后重新访问时造成混乱的方法,并让您继续处理更重要的事情。
Don't worry about the "best method". Just use a method that won't be confusing to revisit later and lets you move on to more important things.