【发布时间】:2023-03-23 21:39:01
【问题描述】:
如何从具有这种格式的 plist 中访问特定的周计划? 如果有人知道与多级结构化 plist 相关的任何教程,请提出建议。
以下代码为我提供了存储在 Plist 中的全部数据
-(void)ReadAppPlist
{
plistPath = [[NSBundle mainBundle] pathForResource:@"runplan" ofType:@"plist"];
NSMutableDictionary * propertyDict = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
name = [propertyDict objectForKey:@"Run - 1"];
NSLog(@"%@",name.description);
}
plist 的格式如下。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Run - 1</key>
<dict>
<key>Level</key>
<string>Beginner</string>
<key>Category</key>
<string>5K</string>
<key>Plan</key>
<dict>
<key>Duration</key>
<string>5week</string>
<key>Week 1</key>
<dict>
<key>Day 1</key>
<string>Rest or run/walk</string>
<key>Day 2</key>
<string>2.5 km run</string>
<key>Day 3</key>
<string>Rest or run/walk</string>
<key>Day 4</key>
<string>2.5 km run</string>
<key>Day 5</key>
<string>Rest</string>
<key>Day 6</key>
<string>2.5 km run</string>
<key>Day 7</key>
<string>30 - 60 min walk</string>
</dict>
<key>Week 2</key>
<dict>
<key>Day 1</key>
<string>Rest or run/walk</string>
<key>Day 2</key>
<string>3 km run</string>
<key>Day 3</key>
<string>Rest or run/walk</string>
<key>Day 4</key>
<string>2.5 km run</string>
<key>Day 5</key>
<string>Rest</string>
<key>Day 6</key>
<string>3 km run</string>
<key>Day 7</key>
<string>35 - 60 min walk</string>
</dict>
</dict>
</dict>
我不知道如何检索这些数据,如果有人知道解决方案,请帮助我... 提前致谢。
【问题讨论】:
-
Run -1 有一个字符串 (Beginner) 用于键 Level,一个字符串 (5K) 用于键 Category,用于键 Plan 的字典等
-
是的,它包含所有详细信息,例如级别、类别、计划。
标签: ios objective-c plist nsmutabledictionary