I want to Merge Two Array With Same Index, This is my JSON
"tier_info": [
{
"tier_id": "1",
"tier_name": "tier-1",
"price": "3.9",
"ios_id": "tier-1",
"android_id": "tier-1"
},
{
"tier_id": "2",
"tier_name": "tier-2",
"price": "4.9",
"ios_id": "tier-2",
"android_id": "tier-2"
},
{
"tier_id": "3",
"tier_name": "tier-3",
"price": "5.9",
"ios_id": "tier-3",
"android_id": "tier-3"
},
{
"tier_id": "4",
"tier_name": "free",
"price": "0",
"ios_id": "free",
"android_id": "free"
}
]
I'm using custom picker, Now I want "tier_name" with "price" in same array index [e.g. "tier_1 : 3.9"]. Code of merging two Array:
NSMutableArray *tierTitles = [[NSMutableArray alloc] init];
tierTitles = [tierArray valueForKey:@"tier_name"];
NSMutableArray *tierPrice = [[NSMutableArray alloc] init];
tierPrice = [tierArray valueForKey:@"price"];
NSMutableArray *combined = [[NSMutableArray alloc] init];
for (NSUInteger i = 0; i < tierArray.count; i++) {
[combined addObject: @{tierTitles[i]:tierPrice[i]}];
}
and i got this
(
{
"tier-1" = "3.9";
},
{
"tier-2" = "4.9";
},
{
"tier-3" = "5.9";
},
{
free = 0;
}
)
i want it like :
(
"tier-1" = "3.9";
"tier-2" = "4.9";
"tier-3" = "5.9";
free = 0;
)
what am i doing wrong here..any correct way to do this?
{"tier-1" = "3.9"; "tier-2" = "4.9"; "tier-3" = "5.9"; free = 0;}(aka one dictionary) not("tier-1" = "3.9"; "tier-2" = "4.9"; "tier-3" = "5.9"; free = 0;)no? Because yours is something strange, the()in print in Objective-C are for a NSArray, and{}for a NSDictionary, and I don't know what's"tier-1" = "3.9";in a NSArray.