title: Receiving 500 error in iphone application because mismatch of data formats
body: <p>I am developing an iPhone application which uses Django as the backend. Web services being developed in Django REST framework post results, Django developer use postman extension to test whether data is actually getting posted.</p>
  
  <p>For example one web service is as follows </p>
  
  <pre><code>class EventCommentPost(generics.ListCreateAPIView):
      """Post a comment to particular Event"""
      # permission_classes = (permissions.IsAuthenticated,)
      model = Event_Comment
      serializer_class = EventCommentSerializer
  
      def post(self,request,*args,**kwargs):
          user_name = request.POST['user_name']
          comment = request.POST['comment']
          event_id = request.POST['event_id']
          UserData = User.objects.get(id = user_name)
          EventData = Event.objects.get(id = event_id)
          Comment = Event_Comment(user_name = UserData,comment =comment,event_id=EventData)
          Comment.save()
          event_comment_id = Event_Comment.objects.get(user_name = UserData,comment =comment,event_id=EventData)
          notification_data = Notification(user_id = EventData.Event_Creator,activity_type = 'Comment',source_id=event_comment_id.id)
          notification_data.save()
          serializer = EventCommentSerializer(event_comment_id)
          list = []
          list.append(serializer.data)
          return Response(list)
  </code></pre>
  
  <p>Now I am using that webservice in my app as follows..</p>
  
  <pre><code>-(void)getDataWithBlokc:(OnComplate)block :(NSString*)strUrl data:(NSDictionary*)dictData
  {
      NSLog(@"POST DATA:=====%@",dictData);
      NSString *hostURL=[NSString stringWithFormat:@"%@%@",HOST_NAME,strUrl];
      NSURL *url=[[NSURL alloc] initWithString:hostURL];
      NSData *jsonData;
      NSString *jsonString;
      if ([NSJSONSerialization isValidJSONObject:dictData])
      {
          jsonData=[NSJSONSerialization dataWithJSONObject:dictData options:0 error:nil];
          jsonString=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  
      }
      request = [NSMutableURLRequest requestWithURL:url];
      [request setHTTPMethod:@"POST"];
      [request setHTTPBody:jsonData];
      [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
      [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[jsonData length]] forHTTPHeaderField:@"Content-Length"];
  
  
      [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
       {
           NSDictionary *dict=[NSDictionary dictionary];
           NSInteger httpStatus = [((NSHTTPURLResponse *)response) statusCode];
           NSLog(@"httpStatus inside block:%ld",(long)httpStatus);
           if ([data length]&gt;0 &amp;&amp; connectionError==nil)
           {
               dict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers|NSJSONReadingAllowFragments error:&amp;connectionError];
  
               block(dict);
           }
           else if (connectionError)
           {
               block(dict);
           }
       }];
  }
  </code></pre>
  
  <p>but this line I am getting 500 status code because of mismatch of data formats</p>
  
  <pre><code>dict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers|NSJSONReadingAllowFragments error:&amp;connectionError];
  </code></pre>