title: How to return only JSON from Zend
body: <p>I'm using Zend Framework 1.x for my project. I want to create a Web service return only JSON string for the caller function. I tried to use <code>Zend_Controller_Action</code> and applied those ways:</p>
  
  <p>1.</p>
  
  <pre><code>$this-&gt;getResponse()
       -&gt;setHeader('Content-type', 'text/plain')
       -&gt;setBody(json_encode($arrResult));
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>$this-&gt;_helper-&gt;getHelper('contextSwitch')
                -&gt;addActionContext('nctpaymenthandler', 'json')
                -&gt;initContext();
  </code></pre>
  
  <p>3.</p>
  
  <pre><code>header('Content-type: application/json');
  </code></pre>
  
  <p>4.</p>
  
  <pre><code>$this-&gt;_response-&gt;setHeader('Content-type', 'application/json');
  </code></pre>
  
  <p>5.</p>
  
  <pre><code>echo Zend_Json::encode($arrResult);
  exit;
  </code></pre>
  
  <p>6.</p>
  
  <pre><code>return json_encode($arrResult);
  </code></pre>
  
  <p>7.</p>
  
  <pre><code>$this-&gt;view-&gt;_response = $arrResult;
  </code></pre>
  
  <p>But when I used cURL to get result, it returned with JSON string surrounded by some HTML tags. Then I tried to user <code>Zend_Rest_Controller</code> with the options above. It still did not success.</p>
  
  <p>P.S.: Most of those ways above are from the question which had been asked on Stack Overflow.</p>