title: JSON parsing using NSJSONSerialization in iOS
body: <p>I am parsing a <code>JSON</code> in my code. But I am getting some unexpected issues while retrieving data of parsed <code>JSON</code>. So let me explain my problem.</p>
  
  <p>I have to parse following <code>JSON</code> data using xcode. This is what data to be parsed looks like while I hit same URL in browser: </p>
  
  <pre><code>{
  "RESPONSE":[
      {"id":"20",
      "username":"john",
      "email":"abc@gmail.com",
      "phone":"1234567890",
      "location":"31.000,71.000"}],
  "STATUS":"OK",
  "MESSAGE":"Here will be message"
  }
  </code></pre>
  
  <p>My code to reach up to this <code>JSON</code> data is as follow: </p>
  
  <pre><code>NSData *data = [NSData dataWithContentsOfURL:finalurl];
  NSError *error;
  NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&amp;error];
  </code></pre>
  
  <p>If I print object <code>json</code> using <code>NSLog</code>, i.e. <code>NSLog(@"json: %@", [json description]);</code> it looks like:</p>
  
  <pre><code>json: {
      MESSAGE = "Here will be message";
      RESPONSE =(
                  {
              email = "abc@gmail.com";
              id = 20;
              location = "31.000,71.000";
              phone = 1234567890;
              username = john;
          }
      );
      STATUS = OK;
  }
  </code></pre>
  
  <p>So, here I observed two things:</p>
  
  <ol>
  <li><p>Sequence of keys (or nodes) (<code>MESSAGE</code>, <code>RESPONSE</code> and <code>STATUS</code>) is changed as compared to web response above.</p></li>
  <li><p>The <code>RESPONSE</code> is get enclosed in <code>'(' &amp; ')'</code> braces. </p></li>
  </ol>
  
  <p>Now if I separate out values for keys <code>MESSAGE</code> &amp; <code>STATUS</code> and <code>NsLog</code>  them, then they get printed as proper string. </p>
  
  <p>Like <code>msgStr:Here will be message</code> &amp;  <code>Status:OK</code></p>
  
  <p><strong>But</strong> if I separate out value for <code>RESPONSE</code> as a dictionary and again separating sub values of that dictionary like <code>email</code> and <code>username</code>, then <strong>I can't getting those as string</strong>. </p>
  
  <p>Here is the code so far I wrote:</p>
  
  <pre><code>NSMutableDictionary *response = [json valueForKey:@"RESPONSE"];
  NSString *username = [response valueForKey:@"username"];
  NSString *emailId = [response valueForKey:@"email"];
  </code></pre>
  
  <p>If I print <code>username</code> and <code>emailId</code>, then they are <strong>not getting printed as normal string</strong>, instead it outputs as: </p>
  
  <pre><code>username:(
      john
  )
  
  email:(
      abc@gmail.com
  )
  </code></pre>
  
  <p>So my question is why it's not getting as a normal string? If I tried to use this variables further then they show value enclosed within <code>'(' &amp; ')'</code> braces. Is this happening because of <code>NSJSONSerialization</code>?</p>