{
“QuizId” : “23566656”
“StartTime”:”23:30”
“EndTime”:”23:45”
“data”:[
{“QuestionID”:”131313131”,“AnswerID”:“1233152”},
{“QuestionID”:”131313141”,“AnswerID”:“1233152”},
{“QuestionID”:”131313151”,“AnswerID”:“1233152”},
{“QuestionID”:”131313161”,“AnswerID”:“1233152”},
{“QuestionID”:”131313171”,“AnswerID”:“1233152”},
{“QuestionID”:”131313181”,“AnswerID”:“1233152”},
{“QuestionID”:”131313191”,“AnswerID”:“1233152”},
{“QuestionID”:”131313101”,“AnswerID”:“1233152”},
]
}
Hello I want to Create a NSDictonary
on Runtime which Structure Should Be Like above. any Help Will Appreciated Thanks.
I Got Solution Thanks For That Effort
Little Change I want to Make As i Have Modal For all Those Data.
let info = self.playQuizArray[currentQuizIndex] as! playInfo
let Ainfo = info.answers[indexPath.row] as! AnswerInfo
let QuesID = info.quizQId
for i in 0..<playQuizArray.count {
data.append(["QuestionID": QuesID[i], "AnswerID": playQuizArray[i]]) // For Answer Ainfo.ansID
}
let dic = [
"QuizId" : "23566656",// info.quizID
"StartTime" : "23:30",
"EndTime" : "23:45",
"data" : data
]
print(dic)
Thanks.
Here Is The Modal
class AnswerInfo: NSObject {
var ansId :String? = ""
var ans :String? = ""
var ansImg :String? = ""
class func infoWith(dict: NSDictionary?) -> AnswerInfo {
let anInfo = AnswerInfo()
anInfo.wrapInfo(dict)
return anInfo
}
func wrapInfo(dict: NSDictionary?) {
if dict == nil {
return
}
self.ansId = dict!.objectForKey("answerId") as? String
self.ans = dict!.objectForKey("AnsImage") as? String
self.ansImg = dict!.objectForKey("option") as? String
}
}
class playInfo: NSObject {
var quizId : String? = ""
var quizQId : String? = ""
var quizQuestion : String? = ""
var answers = NSArray()
class func PlayQuizInfo(dict: NSDictionary?) -> playInfo {
let Pinfo = playInfo()
Pinfo.WrapPlayQuiz(dict)
return Pinfo
}
func WrapPlayQuiz(dict: NSDictionary?) {
if dict == nil {
return
}
self.quizId = dict!.objectForKey("quizId") as? String
self.quizQuestion = dict!.objectForKey("question") as? String
self.quizQId = dict!.objectForKey("questionId")as? String
if let answer = dict?.objectForKey("keys") as? NSArray {
let AnsArray = NSMutableArray()
for ans in answer {
let ansInfo = AnswerInfo.infoWith(ans as? NSDictionary)
AnsArray.addObject(ansInfo)
}
self.answers = AnsArray
}
}
}
See Question&Answers more detail:os