0

I download a list of sports teams. The contents of the JSON list must then be presented in a UIPickerView. Here is the contents of the JSON;

{
 success: "true",
 message: [
{
 category_id: 21,
 category_name: "MAN UTD",
 parent: "EPL"
},
{
 category_id: 22,
 category_name: "Liverpool",
 parent: "EPL"
},
{
 category_id: 27,
 category_name: "Real Madrid",
 parent: "La Liga"
},
{
 category_id: 75,
 category_name: "Barcelona",
 parent: "La Liga"
},
{
 category_id: 23,
 category_name: "Valencia",
 parent: "La Liga"
},
{
 category_id: 24,
 category_name: "Bayern Munich",
 parent: "Bundesliga"
}
]
}

I know how to parse the JSON, but I need to present the UIPickerView with the parent above the associated teams. So I need to add them to an array like so;

EPL, Man Utd, Liverpool, La Liga, Real Madrid, Barcelona, Valencia, Bundesliga, Bayern Munich.

Is there a clean way to do this in a conditional statement? I need to be able to sort them like above, but it would be great if it could handle dynamic content incase the list gets added to etc.

3
  • show the full response data, bz it is easy for optimize the work Commented Jun 30, 2014 at 11:30
  • @Anbu.Karthik ok, please see above Commented Jun 30, 2014 at 11:33
  • [self.arrNames sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];; above method is for arrange mutable values in ascending order Commented Jun 30, 2014 at 11:39

1 Answer 1

2
// First Store Json Data in To NSArray       

 // NSSortDescriptor (better)

  NSSortDescriptor *sortDescriptor;
  sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"parent"
                                              ascending:YES];
  NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
  NSArray *sortedArray;
  sortedArray = [drinkDetails sortedArrayUsingDescriptors:sortDescriptors];
Sign up to request clarification or add additional context in comments.

1 Comment

Very good, but how would I add the parent name to the list before its children, like in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.