gpt4 book ai didi

ios - 在 NSDictionary 中知道其中一个键值时获取其他键值

转载 作者:行者123 更新时间:2023-11-29 13:32:45 26 4
gpt4 key购买 nike

<array>
<array>
<dict>
<key>UserName</key>
<string>BMWM6</string>
<key>Engine</key>
<string>4.0</string>
<key>Image</key>
<string>bmwM6.png</string>
<key>Dealers</key>
<string>USA</string>
<key>Phone</key>
<string>10000</string>
<key>Price</key>
<string>68</string>
<key>Category</key>
<string>BMW</string>
</dict>
<dict>
<key>UserName</key>
<string>BMWi740</string>
<key>Engine</key>
<string>4.0</string>
<key>Image</key>
<string>bmwM6.png</string>
<key>Dealers</key>
<string>NewYork</string>
<key>Phone</key>
<string>13800138000</string>
<key>Price</key>
<string>235</string>
<key>Category</key>
<string>BMW</string>
</dict>
<dict>
<key>UserName</key>
<string>BMWX6</string>
<key>Engine</key>
<string>3.0</string>
<key>Image</key>
<string>bmwM6.png</string>
<key>Dealers</key>
<string>NewYork</string>
<key>Phone</key>
<string>13800138000</string>
<key>Price</key>
<string>231</string>
<key>Category</key>
<string>BMW</string>
</dict>
</array>
<array>
<dict>
<key>UserName</key>
<string>E60</string>
<key>Engine</key>
<string>3.5</string>
<key>Image</key>
<string>BenzE60.png</string>
<key>Dealers</key>
<string>NewYork</string>
<key>Phone</key>
<string>13800138000</string>
<key>Price</key>
<string>180</string>
<key>Category</key>
<string>BENZ</string>
</dict>
</array>
<array>
<dict>
<key>UserName</key>
<string>R8</string>
<key>Engine</key>
<string>4.5</string>
<key>Image</key>
<string>audiR8.png</string>
<key>Dealers</key>
<string>NewYork</string>
<key>Phone</key>
<string>13800138000</string>
<key>Price</key>
<string>220</string>
<key>Category</key>
<string>AUDI</string>
</dict>
</array>

我有这个 plist。一旦我得到“BMWM6”的值,我如何知道数组中同一字典中的另一个值?你能帮我一些忙吗?提前致谢。就像这样:我知道 BMWM6 这个值,所以我想知道其他键值,如 Engine/Dealers/Phone 等等。

最佳答案

假设 plistArray 是你的 plist 内容:

NSString *username = @"BMWM6";
NSPredicate *pre = [NSPredicate predicateWithFormat:@"UserName = %@", username];
NSDictionary *resultDict = [[plistArray filteredArrayUsingPredicate:pre] lastObject];

// now you have the dictionary
// dealer:
NSString *dealers = [resultDict objectForKey:@"Dealers"];
NSLog(@"dealers: %@", dealers);

关于ios - 在 NSDictionary 中知道其中一个键值时获取其他键值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11449369/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com