How to integrate NSUrlsession in ios
<p>Hi I am very new to ios and in my app I am using NSUrlSession for integrating services.</p>

<p>Here my main problem is when I get a response from the server, I can't handle them properly.</p>

<h2>When I get a correct response, then see the below json stucture:-</h2>

<pre><code>responseObject = {

           {
            Name = Broad;
            DeptNo = A00;
            BatchNo = 23;
            DeptId = 120;
          },

          {
            Name = James;
            DeptNo = B00;
            BatchNo = 23;
            DeptId = 123;
          },
     }
</code></pre>

<h2>when I get a wrong response, see the below json stucture:-</h2>

<pre><code>responseObject = {

    error = 1;
    message = "Invalid Code";
}
</code></pre>

<p>when  I get a correct response from the server, I am getting an exception in my below <code>if block(like __NSCFArray objectForKey:]: unrecognized selector sent to instance 0x1611c200')</code> and when I get a wrong response then T get exception in my <code>else block</code></p>

<p>Please help me how to handle them</p>

<h2>my code:-</h2>

<pre><code> (void) GetCallService1: (id)MainResponse{

    dispatch_async(dispatch_get_main_queue(), ^{

        NameArray = [[NSMutableArray alloc]init];
        IdArray = [[NSMutableArray alloc]init];


            if([MainResponse objectForKey:@"error"] != nil)
            {
                NSLog(@"No data available");
            }
            else{
        for (NSDictionary *obj in MainResponse) {

            if([obj objectForKey:@"Name"] &amp;&amp; [obj objectForKey:@"DeptNo"])    {

                NSString * Name = [obj objectForKey:@"Name"];
                [NameArray addObject:Name];
                NSString * Id = [obj objectForKey:@"id"];
                [IdArray addObject:Id];
            }
           }
        }
    });
}
</code></pre>