Ok. Let me explain the solution. As you said in the comment, you are using the library throughout the app.
So, I think the best solution to your problem is create the OrderedDictionary from CocoaWithLove. The OrderedDictionary contains an NSMutableDictionary and an NSMutableArray for the keys inside it, to keep track of the order of the keys.
The you can create a Category of FMResultSet:
FMResultSet+OrderedDict.h
#import <Foundation/Foundation.h>
#import "FMResultSet.h"
#import "OrderedDictionary.h"
@interface FMResultSet(OrderedDict)
- (OrderedDictionary*)resultOrderDictionary;
@end
FMResultSet+OrderedDict.m
#import "FMResultSet+OrderedDict.h"
#import "OrderedDictionary.h"
#import "FMDatabase.h"
@implementation FMResultSet(OrderedDict)
- (OrderedDictionary*)resultOrderDictionary {
NSUInteger num_cols = (NSUInteger)sqlite3_data_count([_statement statement]);
if (num_cols > 0) {
OrderedDictionary *dict = [OrderedDictionary dictionaryWithCapacity:num_cols];
int columnCount = sqlite3_column_count([_statement statement]);
int columnIdx = 0;
for (columnIdx = 0; columnIdx < columnCount; columnIdx++) {
NSString *columnName = [NSString stringWithUTF8String:sqlite3_column_name([_statement statement], columnIdx)];
id objectValue = [self objectForColumnIndex:columnIdx];
[dict setObject:objectValue forKey:columnName];
}
return dict;
}
else {
NSLog(@"Warning: There seem to be no columns in this set.");
}
return nil;
}
@end
And in your code do this:
NSMutableArray *results = [NSMutableArray array];
while ([Loginresults next]) {
[results addObject:[Loginresults resultOrderDictionary]];
}
requestdata = [NSJSONSerialization dataWithJSONObject:results options:0 error:&jsonError];
If you want I can upload my Project Test to github.
EDIT: The code now is uploaded.