i am working on a project in which i have an array which contain a dictionary which is in the given form i have to get the value of "Size_val" on the basis of "size_key".
array : (
{
"as_per_size" = {
lowercatname = abcd;
sizes = (
{
"size_key" = "UP_CHEST";
"size_name" = "UP_CHEST";
"size_val" = 4;
typecat = 1;
},
{
"size_key" = LENGTH;
"size_name" = LENGTH;
"size_val" = 1;
typecat = 1;
},
{
"size_key" = DP;
"size_name" = DP;
"size_val" = 3;
typecat = 1;
},
{
"size_key" = "YOKE_LENGTH";
"size_name" = "YOKE_LENGTH";
"size_val" = 2;
typecat = 1;
},
{
"size_key" = KNEE;
"size_name" = KNEE;
"size_val" = 2;
typecat = 2;
},
{
"size_key" = THIGH;
"size_name" = THIGH;
"size_val" = 1;
typecat = 2;
},
{
"size_key" = CALF;
"size_name" = CALF;
"size_val" = 3;
typecat = 2;
}
);
uppercatname = CHOLI;
};
i just only want to get the value of "Size_val" on the basis of "size_key". i use the code to get the value of uppercatname.
upstring1 = [[[arrFilteredOrder objectAtIndex:0] objectForKey:@"as_per_size"] objectForKey:@"uppercatname"];
TypeLabel.text = upstring1;
please give me some solution how to get this value
Apparently your sizes values is also an array, so you have to get this array first, then loop through the sizes array to get the size dictionaries, and from the size dictionaries get the right size_val for the size_key you have.
So for the first entry and your size key:
NSArray* sizes = [[[arrFilteredOrder[0] objectForKey:@"as_per_size"] objectForKey;@"sizes];
foreach(NSDictionary* sizeDict in sizes {
NSString* sizeKey = sizeDict[@"size_key];
if([sizeKey isEqualToString:<your size key>])
{
NSString* sizeVal = sizeDict[@"size_val"];
// now do something with your value
...
}
}