[问题] 读取NSMutableArray特定位置的值、修正输出顺序

楼主: Talenius (Harmonic Inspirations)   2016-02-28 11:23:24
已先使用FMDB读取sqlite的某一table J的值
程式:
NSMutableArray* JData = [NSMutableArray arrayWithCapacity: 0];
FMResultSet *rs = [db executeQuery: @"SELECT uid, uidY, uidH, uidT, uidO from J"];
while ([rs next]) {
int uid = [rs intForColumn: @"uid"];
int uidY = [rs intForColumn: @"uidY"];
int uidH = [rs intForColumn: @"uidH"];
int uidT = [rs intForColumn: @"uidT"];
int uidO = [rs intForColumn: @"uidO"];
[JData addObject: [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: uid], @"uid",
[NSNumber numberWithInt: uidY], @"uidY",
[NSNumber numberWithInt: uidH], @"uidH",
[NSNumber numberWithInt: uidT], @"uidT",
[NSNumber numberWithInt: uidO], @"uidO",
nil]];
}
NSLog(@"%@", JData[2]);
结果:
uid = 3;
uidH = 0;
uidO = 3;
uidT = 0;
uidY = 98;
程式设计的目的:
读取table J的值转成二维阵列
以便直接读取特定位置的值进行运算
请问:
1. 输出结果顺序与读取顺序不同,应如何修正?
读取sqlite的table J字段顺序:uid, uidY, uidH, uidT, uidO
但显示读取后的字段值顺序却是:uid, uidH, uidO, uidT, uidY
2. 如何读取特定位置的值?
数据库就像二维阵列
虽然可以读取某列的值(如:JData[2]列出uid, uidH, uidO, uidT, uidY)
但要如何读取某列某行的值(如:JData[2][2])
谢谢
作者: appleway (苹果爱天空)   2016-02-28 11:28:00
JData[2][@"uid"], JData[2][@"uidH"], etc
作者: tentenlee (天天)   2016-02-28 13:25:00
nsdictionary的key没有顺序的概念 只能在使用的时候去排顺序 你要用JData[2][2]的话里面的资料要是array不然依照目前结构的话就用一楼的那个方式就可以了
楼主: Talenius (Harmonic Inspirations)   2016-02-28 23:20:00
感谢指点

Links booklink

Contact Us: admin [ a t ] ucptt.com