gpt4 book ai didi

ios - 无法通过 nsdictionary 中的键访问值

转载 作者:行者123 更新时间:2023-11-30 13:52:08 26 4
gpt4 key购买 nike

我很困惑这是什么问题,我的字典是:

eventDetails = (WebHandler.sharedInstance.eventsDictionary?.copy())! as! NSDictionary


print("Printing eventdeatails: '\(eventDetails)'")

Printing event details: '{
0 = {
"_id" = 5661958b2c0fee491a9e9e08;
date = "9am - 1pm";
degree = ee;
eventCategory = sports;
eventDescription = "cricket match between east and west wing";
eventPhoto = "";
eventTitle = "cricket match";
location = "west wing hall";
society = "the society that has nothing better to do";
universityId = ucf;
};
3 = {
"_id" = 5661981b69439a6a1b17870e;
date = "8am - 3pm";
degree = ee;
eventCategory = sports;
eventDescription = "football match between batch 13 and 14";
eventPhoto = "";
eventTitle = "football match";
location = "west wing hall";
society = "King KOng";
universityId = ucf;
};
1 = {
"_id" = 566195a72c0fee491a9e9e09;
date = "8am - 3pm";
degree = ee;
eventCategory = sports;
eventDescription = "football match between batch 13 and 14";
eventPhoto = "";
eventTitle = "football match";
location = "west wing hall";
society = "King KOng";
universityId = ucf;
};
2 = {
"_id" = 566195b12c0fee491a9e9e0a;
date = "8am - 3pm";
degree = ee;
eventCategory = entertainment;
eventDescription = "showing the harry potter!";
eventPhoto = "";
eventTitle = "movie showing";
location = "west wing hall";
society = "the society that has nothing better to do";
universityId = ucf;
};
}'

这就是我从网络处理程序类中获取它的方式。我设置了非常简单的键 0、1、2...,以便在需要时轻松使用。它正确打印完整的字典,但每当我尝试访问该值时,它都会让我获取这些特定值,而不是得到“nil”结构是我有 dict 和 dict 我现在尝试过的是

let key = "2"
print(eventDetails[key]!) //not working

print(eventDetails["2"]!) // just for confirmation, not working

print(eventDetails["2"]!["_id"]!) // not working
print(eventDetails.valueForKey(idnumber)) // i have doubt on word "key" so i changed it and observed it but not good for me

请帮我推荐一些好的读物或一些可以找到基础知识或给我一些出路的东西。我现在一无所知。提前致谢!

最佳答案

您的字典由整数值作为键,因此您必须使用 NSInteger(或 Int)类型的键访问字典。尝试:

let key = 2
print(eventDetails[key]!)
print(eventDetails[2]!)

关于ios - 无法通过 nsdictionary 中的键访问值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34130637/

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