如何将 NSDictionary 主密钥保存在 NSString 中?
我有一个具有以下结构的 plist:
<plist version="1.0">
<dict>
<key>000001</key>
<dict>
<key>name</key>
<string>Peter</string>
.
.
</dict>
<key>000002</key>
<dict>
<key>name</key>
<string>Jack</string>
.
.
</dict>
.
.
</dict>
</plist>
我使用这个 plist 创建一个表视图,当用户选择一个单元格时,我需要使用相应内部字典的数据加载另一个视图。我想到了一种方法来做到这一点,但我需要能够保存 000001 类型的键,比如 NSString *dictKey = [innerDict getMasterKey] 之类的东西,这样的东西存在吗?
编辑:我忘了提及我正在从服务器上的 json 文件构建 plist,所以我根本无法修改 plist 结构。
I have a plist with the following structure:
<plist version="1.0">
<dict>
<key>000001</key>
<dict>
<key>name</key>
<string>Peter</string>
.
.
</dict>
<key>000002</key>
<dict>
<key>name</key>
<string>Jack</string>
.
.
</dict>
.
.
</dict>
</plist>
I'm using this plist to create a table view, when the user selects a cell, I need to load another view with the data of the corresponding inner dictionary. I thought of a way to do this, but I need to be able to save the 000001 type keys, something like NSString *dictKey = [innerDict getMasterKey] or something, does such a thing exist?
EDIT: I forgot to mention I am building the plist from a json file on a server, so I can't modify the plist structure at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不将值传递给下一个视图控制器,即声明一个属性来存储密钥。我很确定 getMasterKey 不会存在,因为该对象可以同时包含在许多数组和字典中,因此您无法回溯,除非您保留某种指示器,在这种情况下最好由视图控制器中的属性。
或者,您可以考虑
关联对象
。您可以查看此文档的示例
网上还有更多。然而,在我看来,这有点过头了,除非你有一个非常具体的目的,使用属性不起作用。Why don't you just pass the value along to the next view controller i.e. declare a property to store the key. I am pretty sure
getMasterKey
won't exist as the object can be include in many arrays and dictionaries at once so you can't backtrace unless you keep sort of indicator which in this case is best served by a property in the view controller.Alternatively, you can consider
associated objects
. You can look at this document for anexample
and there are a few more on the net. However this would be overdoing it in my opinion unless you've a very specific purpose that using properties won't work.在字典中粘贴“MasterKey”/“00001”键/值对......
Stick a "MasterKey" / "00001" key/value pair in the dictionary....