Reputation: 3813
Its only outputting one set for NSMutableDictionary not both. I want to create an JSON request using NSMutableDictionary (JSONRepresentation).
// My code
NSArray *keysEndpoint = [NSArray arrayWithObjects:@"ID", @"Name", @"EndpointType", nil];
NSArray *objectEndpoint = [NSArray arrayWithObjects:@"622", @"Brand", @"0", nil];
NSArray *keysEndpoint1 = [NSArray arrayWithObjects:@"ID", @"Name", @"EndpointType", nil];
NSArray *objectEndpoint1 = [NSArray arrayWithObjects:@"595", @"CK-05052011", @"1", nil];
NSMutableArray *keys1 = [[NSMutableArray alloc] initWithCapacity:0];
NSMutableArray *objects1 = [[NSMutableArray alloc] initWithCapacity:0];
[keys1 addObjectsFromArray:keysEndpoint];
[keys1 addObjectsFromArray:keysEndpoint1];
NSLog(@"Key Dic: %@", keys1);
[objects1 addObjectsFromArray:objectEndpoint];
[objects1 addObjectsFromArray:objectEndpoint1];
NSLog(@"Obje Dic: %@", objects1);
NSMutableDictionary *testMut = [NSMutableDictionary dictionaryWithObjects:objects1 forKeys:keys1];
NSLog(@"Test Dic: %@", testMut);
Output is am getting is this:
Test Dic: {
EndpointType = 1;
ID = 595;
Name = "CK-05052011";
}
Expexted output i want is :
Test Dic: {
EndpointType = 1;
ID = 595;
Name = "CK-05052011";
}
{
EndpointType = 0;
ID = 622;
Name = "Brand";
}
Upvotes: 0
Views: 148
Reputation: 7986
For a dictionary, adding the same keys twice will override the first set of keys. You should have a NSMutableArray of NSMutableDictionary
NSArray *keysEndpoint = [NSArray arrayWithObjects:@"ID", @"Name", @"EndpointType", nil];
NSArray *objectEndpoint = [NSArray arrayWithObjects:@"622", @"Brand", @"0", nil];
NSArray *keysEndpoint1 = [NSArray arrayWithObjects:@"ID", @"Name", @"EndpointType", nil];
NSArray *objectEndpoint1 = [NSArray arrayWithObjects:@"595", @"CK-05052011", @"1", nil];
NSMutableDictionary *testMut = [NSMutableDictionary dictionaryWithObjects:objectsEndpoint forKeys:keysEndpoint];
NSMutableDictionary *testMut1 = [NSMutableDictionary dictionaryWithObjects:objectsEndpoint1 forKeys:keysEndpoint1];
NSMutableArray * dictArray = [NSMutableArray arrayWithObjects:testMut,testMut1,nil];
NSLog(@"Test DictArray: %@", dictArray);
Upvotes: 1