-4

I am New to iOS developement.I have response string like below :

{"7":"Afghanistan","8":"Albania","9":"Algeria","10":"Andorra","11":"Angola","12":"Antigua and Barbuda","13":"Argentina","14":"Armenia","15":"Austria","16":"Azerbaijan","17":"Bahamas","18":"Bahrain","19":"Bangladesh","20":"Barbados","21":"Belarus","22":"Belgium","23":"Belize","24":"Benin","25":"Bhutan","26":"Bolivia","27":"Bosnia and Herzegovina","28":"Botswana","29":"Brazil","30":"Brunei","31":"Bulgaria","32":"Burkina Faso","33":"Burundi","34":"Cambodia","35":"Cameroon","36":"Canada","37":"Cape Verde","38":"Central African Republic","39":"Chad","40":"Chile","41":"China","42":"Colombia","43":"Comoros","44":"Costa Rica","45":"Cote d'Ivoire","46":"Croatia","47":"Cuba","48":"Cyprus","49":"Czech Republic","50":"Democratic Republic of the Congo","51":"Denmark","52":"Djibouti","53":"Dominica","54":"Dominican Republic","55":"East Timor","56":"Ecuador","57":"Egypt","58":"El Salvador","59":"Equatorial Guinea","60":"Eritrea","61":"Estonia","62":"Ethiopia"}

Please help me to get country name list.

Kunal
  • 83
  • 1
  • 2
  • 11

3 Answers3

2

try below code to parse JSON Data above iOS 5

NSError *jsonError = nil;
NSDictionary *tempDict = [NSJSONSerialization JSONObjectWithData:JsonData options:0 error:&jsonError]; 
// here JsonData is nsmutabledata in which your response is append 
NSLog(@"%@",tempDict);

try this you will be succeed use iOS version 5.0 an above then 5.0

Pratik
  • 2,399
  • 17
  • 36
0

I think you don't know JSON parsing.

Search "iOS JSON Parsing" in google and you will get many tutorial for that.

LEt me list few here for you.

1 . Working with JSON in iOS 5 Tutorial
2 . JSON Framework for iPhone
3 . How to parse JSON in iOS App

Learn JSON parsing try to do it in your app and if you face problem in that than post it here.

Community
  • 1
  • 1
CRDave
  • 9,279
  • 5
  • 41
  • 59
0

you need first to do the following: You embed this code in your viewdidLoad function:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http:your URL path for json file"]];
    [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});

then you have to add this function:

-(void)fetchedData:(NSData *)responseData{
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
jsonResults = [json objectForKey:@"Content"];
}

[self.tableView reloadData];

}

hope this will help you

CarinaM
  • 527
  • 4
  • 12
  • 27