<dict> <key>11231654</key> <array> <string>hello</string> <string>goodbye</string> </array> <key>78978976</key> <array> <string>ok</string> <string>cancel</string> </array>
我用这个加载了pList:
Nsstring *path = [[NSBundle mainBundle] pathForResource: @"data" ofType:@"pList"]; // Build the array from the pList NSMutableArray *array3 = [[NSMutableArray alloc] initWithContentsOffile:path];
我怎样才能访问我的pList的每个元素?
我想在pList中搜索匹配的键,而不是搜索其子项.我怎样才能做到这一点?有什么建议吗?
请提前!
解决方法 数组已编入索引.如果要访问NSArray中的第一个对象,则执行以下 *** 作:ID someObject = [array objectAtIndex:0];
如果你知道对象类型,你可以这样做:
Nsstring *myString = [array objectAtIndex:0];
编辑:您需要使用NSDictionary来获取您拥有的数据 – 请注意它以< dict>开头.标签,而不是< array> tag(尽管有数组作为值).
Nsstring *path = [[NSBundle mainBundle] pathForResource: @"data" ofType:@"pList"];// Build the array from the pList NSDictionary *dict = [[NSDictionary alloc] initWithContentsOffile:path];NSArray *value = [dict valueForKey:@"11231654"];
现在,您可以使用阵列执行任何 *** 作.
总结以上是内存溢出为你收集整理的objective-c – 访问plist数据全部内容,希望文章能够帮你解决objective-c – 访问plist数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)