找出一个对象是否存在于 plist 中?

发布于 2024-09-04 15:37:01 字数 431 浏览 2 评论 0原文

如果我有一个已放入数组的 plist,看起来像这样

-Root
   -Item 0        Dictionary
      Name        String         Henry
      Kids        Array
         -Item 0  String         Lindy
         -Item 1  String         Paul
   -Item 1        Dictionary
      Name        String         Janet
      Pets        Array
         -Item 0  String         Snoopy
         -Item 1  String         Pebbles

如何找出每个人是否有孩子或宠物?

If I have a plist which I have put into and array, which looks something like this

-Root
   -Item 0        Dictionary
      Name        String         Henry
      Kids        Array
         -Item 0  String         Lindy
         -Item 1  String         Paul
   -Item 1        Dictionary
      Name        String         Janet
      Pets        Array
         -Item 0  String         Snoopy
         -Item 1  String         Pebbles

How can find out whether each person has kids or pets?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热风软妹 2024-09-11 15:37:01

您可以使用 valueForKey:key 查询 NSDictionary
//如果键值不存在,则返回nil。

NSDictionary *person = read the person to this..

if(nil == [person valueForKey:@"Kids"])
{
  //has no kids..
}
else
{
 //has kids
}

if(nil == [person valueForKey:@"Pets"])
{
  //has no pets..
}
else
{
 //has pets
}

You can query NSDictionary with valueForKey:key
//returns nil, if valued for key is not present.

NSDictionary *person = read the person to this..

if(nil == [person valueForKey:@"Kids"])
{
  //has no kids..
}
else
{
 //has kids
}

if(nil == [person valueForKey:@"Pets"])
{
  //has no pets..
}
else
{
 //has pets
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文