FMDB 结果集到字典中 [英] FMDB resultset into dictionary
本文介绍了FMDB 结果集到字典中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种简单的方法可以将 executeQuery:SELECT * ...
的 FMDB 结果轻松放入字典中?
Is there an easy way to get the FMDB results of an executeQuery:SELECT * ...
easily into a dictionary?
FMResultSet *appointmentResults = [[DataClass getDB] executeQuery:@"SELECT * FROM Appointments WHERE date = ?",currDateString];
while ([appointmentResults next]) {
//Create dictionary
//Add dictionary to array for later use
}
我想知道是否有一种方法可以让字典将列名作为键,将值作为列值.最好不必循环遍历 while 中的每一行.
I was wondering if there was a way I could make the dictionary keys the column names and the values the column values. Preferably without having to do a loop through every row inside the while.
推荐答案
是的:
NSMutableArray *results = [NSMutableArray array];
FMResultSet *appointmentResults = [[DataClass getDB] executeQuery:@"SELECT * FROM Appointments WHERE date = ?",currDateString];
while ([appointmentResults next]) {
[results addObject:[appointmentResults resultDictionary]];
}
-resultDictionary
是 FMResultSet
的内置方法,它将把当前元组转换为 NSDictionary,以列名为键.
-resultDictionary
is a built-in method on FMResultSet
that will turn the current tuple into an NSDictionary, keyed by column name.
这篇关于FMDB 结果集到字典中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文