NSMutableDictionary 未获得预期输出。
它只为 NSMutableDictionary 输出一组,而不是两者。我想使用 NSMutableDictionary (JSONRepresentation) 创建 JSON 请求。
// 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);
我得到的输出是这样的:
Test Dic: {
EndpointType = 1;
ID = 595;
Name = "CK-05052011";
}
我想要的Expexted输出是:
Test Dic: {
EndpointType = 1;
ID = 595;
Name = "CK-05052011";
}
{
EndpointType = 0;
ID = 622;
Name = "Brand";
}
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";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于字典,添加相同的键两次将覆盖第一组键。你应该有一个 NSMutableArray 的 NSMutableDictionary
For a dictionary, adding the same keys twice will override the first set of keys. You should have a NSMutableArray of NSMutableDictionary