title: XML into JSON conversion in iOS
body: <p>I need to convert XML response to JSON. </p>
  
  <p>My XML response:</p>
  
  <pre><code>&lt;commands&gt;
  &lt;command id="0" name="GetAPPsProducts"&gt;
    &lt;command_parameters&gt;
      &lt;command_parameter id="0" name="APPs_Code"&gt;ATAiOS&lt;/command_parameter&gt;
    &lt;/command_parameters&gt;
    &lt;command_result&gt;
      &lt;apps_products&gt;
        &lt;apps_products id="1"&gt;
          &lt;apps_code&gt;ATAiOS&lt;/apps_code&gt;
          &lt;apps_product_id&gt;2&lt;/apps_product_id&gt;
          &lt;brand_id&gt;2&lt;/brand_id&gt;
          &lt;brand_desc&gt;Generic&lt;/brand_desc&gt;
          &lt;brand_product_id&gt;2&lt;/brand_product_id&gt;
          &lt;product_id&gt;001-7&lt;/product_id&gt;
          &lt;descrizione&gt;MyTravelApp&lt;/descrizione&gt;
        &lt;/apps_products&gt;
      &lt;/apps_products&gt;
    &lt;/command_result&gt;
  &lt;/command&gt;
  </code></pre>
  
  <p></p>
  
  <p>I am using XMLReader supporting file from this site:  </p>
  
  <p><a href="http://troybrant.net/blog/2010/09/simple-xml-to-nsdictionary-converter/" rel="noreferrer">XMLReader</a></p>
  
  <p>I am using this code to convert XML to JSON</p>
  
  <pre><code>NSError *parseError = nil;
  NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:testXMLString error:&amp;parseError];
  NSLog(@" %@", xmlDictionary);
  </code></pre>
  
  <p>I got JSON response like this:</p>
  
  <pre><code>commands =         {
          command =             {
              "command_parameters" =                 {
                  "command_parameter" =                     {
                      id = 0;
                      name = "APPs_Code";
                      text = "\n  \n    \n      \n        ATAiOS";
                  };
                  text = "\n      ";
              };
              "command_result" =                 {
                  "apps_products" =                     {
                      "apps_products" =                         {
                          "apps_code" =                             {
                              text = "\n      \n        \n          \n            ATAiOS";
                          };
                          "apps_product_id" =                             {
                              text = "\n            2";
                          };
                          "brand_desc" =                             {
                              text = "\n            Generic";
                          };
                          "brand_id" =                             {
                              text = "\n            2";
                          };
                          "brand_product_id" =                             {
                              text = "\n            2";
                          };
                          descrizione =                             {
                              text = "\n            MyTravelApp";
                          };
                          id = 1;
                          "product_id" =                             {
                              text = "\n            001-7";
                          };
                          text = "\n          ";
                      };
                      text = "\n        ";
                  };
                  text = "\n      ";
              };
              id = 0;
              name = GetAPPsProducts;
              text = "\n    ";
          };
          text = "\n  ";
      };
      text = "\n  \n";
  };
  </code></pre>
  
  <p>I need response like this:</p>
  
  <pre><code>  {
    "commands": {
      "command": {
        "-id": "0",
        "-name": "GetAPPsProducts",
        "command_parameters": {
          "command_parameter": {
            "-id": "0",
            "-name": "APPs_Code",
            "#text": "ATAiOS"
          }
        },
        "command_result": {
          "apps_products": {
            "apps_products": {
              "-id": "1",
              "apps_code": "ATAiOS",
              "apps_product_id": "2",
              "brand_id": "2",
              "brand_desc": "Generic",
              "brand_product_id": "2",
              "product_id": "001-7",
              "descrizione": "MyTravelApp"
            }
  </code></pre>
  
  <p>I get this response while conversion in online. How to get response like this. </p>
  
  <p>Thanks in Advance.  </p>