0

I need read one webservice that return jsonarry in my iphone application. After this reading, i will need make load this information in my tableview.

But the return is one string, how make transform this string in one format that my table view understand.

following example return

{"codUf":28,"descricao":"MG"},{"codUf":29,"descricao":"PR"},{"codUf":19,"descricao":"RJ"},{"codUf":25,"descricao":"SP"}]

Thanks !!

1 Answers1

1

If you're using ios5, following the tutorial:

#define kBgQueue dispatch_get_global_queue(
 DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) //1

dispatch_async(kBgQueue, ^{
        NSData* data = [NSData dataWithContentsOfURL: 
          kLatestKivaLoansURL];
        [self performSelectorOnMainThread:@selector(fetchedData:) 
          withObject:data waitUntilDone:YES];
    });

NSDictionary* json = [NSJSONSerialization 
        JSONObjectWithData:responseData //1

        options:kNilOptions 
        error:&error];

Now your JSON data should be in the json dictionary. Good luck and if you have further problems, do leave a comment.

hd1
  • 32,598
  • 5
  • 75
  • 87
  • Thank you for your help ! But I have more one question ! my webservice was done in c# and return json., this tutorial will help me ? – user2311749 Apr 28 '13 at 01:30
  • @user2311749 JSON is JSON. It makes no difference how it was created. It could be generated from PHP, Java, or monkeys banging on typewriters. The same Objective-C code can parse any valid JSON. – rmaddy Apr 28 '13 at 05:23
  • @user2311749 JSON is just a transmission format. It can be generated using a text editor and look like it was generated by C#. – hd1 Apr 28 '13 at 05:26
  • Ok, thank you for your help, but now my problem is in done the parce, because the webservice return is a string and I don't know how done this parce. – user2311749 Apr 28 '13 at 12:02
  • Please [see here](http://stackoverflow.com/questions/4147324/how-can-i-initialize-an-nsdata-object-with-a-string-instead-of-a-file) for the answer to your question. – hd1 Apr 28 '13 at 12:35