title: How to convert NSString to NSDictionary in objective c?
body: <p>Hi am new to objective C, Thanks in advance for any help.</p>
  
  <pre><code>- (void)application:(UIApplication *)application
  didReceiveRemoteNotification:(NSDictionary *)userInfo
  {
  
      NSLog(@"Notification Received: %@", userInfo);
      NSString *NSSMessage = [NSString stringWithFormat:@"%@", userInfo];
  
      NotificationMessageHandler *obj = [[NotificationMessageHandler alloc] init];
      [obj handleNotificationMessage: NSSMessage]; // NSSmessage is a string to convert into JSON
  
  }
  </code></pre>
  
  <p>I had following as NSString in NSSMessage </p>
  
  <pre><code>{
      aps =     {
          alert = "\"Status\":\"Confirm\",\"Location\":\"\",\"Type\":\"Telephone Consultation\",\"Date\":\"2015-01-05\",\"Time\":\"19:03\",\"RescheduleDate\":\"\"";
          badge = 1;
          sound = "beep.wav";
      };
  }
  </code></pre>
  
  <p>Inside handleNotificationMessage, am converting NSString to JSON format</p>
  
  <pre><code>- (void) handleNotificationMessage : (NSString *) NSSParam
  {
  
      if(NSSParam != nil &amp;&amp; NSSParam != Nil)
      {
  
          // Parse the string
          NSLog(@"NSS Message Param %@", NSSParam);
  
  
          NSSParam = [NSSParam stringByReplacingOccurrencesOfString:@" "
                                                              withString:@""];
          NSSParam = [NSSParam stringByReplacingOccurrencesOfString:@"\n"
                                                                 withString:@""];
  
  
          NSSParam = [NSSParam stringByReplacingOccurrencesOfString:@"aps="
                                                         withString:@"\"aps\":"];
          NSSParam = [NSSParam stringByReplacingOccurrencesOfString:@"alert=\""
                                                         withString:@"\"alert\":{"];
          NSSParam = [NSSParam stringByReplacingOccurrencesOfString:@"\"\";"
                                                         withString:@"\"},"];
  
          NSSParam = [NSSParam stringByReplacingOccurrencesOfString:@"badge="
                                                         withString:@"\"badge\":"];
          NSSParam = [NSSParam stringByReplacingOccurrencesOfString:@"sound="
                                                         withString:@"\"sound\":"];
  
          NSSParam = [NSSParam stringByReplacingOccurrencesOfString:@"}}\""
                                                         withString:@"}}"];
  
          NSSParam = [NSSParam stringByReplacingOccurrencesOfString:@";"
                                                                             withString:@","];
          NSSParam = [NSSParam stringByReplacingOccurrencesOfString:@",},}"
                                                         withString:@"}}"];
  
          NSLog(@"NSS Message Param After Parsing %@", NSSParam);
  
               NSData *data = [NSSParam dataUsingEncoding:NSUTF8StringEncoding];
          id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; // Here json is null
  }
  }
  </code></pre>
  
  <p>After parsing i had a JSON as following</p>
  
  <pre><code>{"aps":{"alert":{\"Status\":\"Confirm\",\"Location\":\"\",\"Type\":\"TelephoneConsultation\",\"Date\":\"2015-01-05\",\"Time\":\"20:15\",\"RescheduleDate\":\"\"},"badge":1,"sound":"beep.wav"}}
  </code></pre>
  
  <p>I had used following code to convert from NSString to JSON</p>
  
  <pre><code>NSData *data = [NSSParam dataUsingEncoding:NSUTF8StringEncoding];
  id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; // Here json is null
  </code></pre>
  
  <p>Here json object shows null but NSData has object.
  So, How to convert NSString to NSDictionary in objective c?
  Please help !</p>