title: Zend_JSON:Encode messing up - why?
body: <p>My Zend_Json is messing up in encoding an object here. I'm encoding an associative array which has two elements:
  Element one is another associative array while element 2 is an HTML string. He's goofing up such that the Html string part contains just NULL!!?!?!?!?</p>
  
  <p>Heres the element UNencoded when I do a var_dump on it...sorry for the looong element...
  Its very erratic - I don't understand whats wrong here...</p>
  
  <pre><code>array (
    'map' =&gt; 
    array (
      0 =&gt; 
      array (
        'id' =&gt; '1403',
        'name' =&gt; 'Amborovy Airport (Philibert Tsiranana Airport)',
        'label' =&gt; 'Amborovy Airport (Philibert Tsiranana Airport)',
        'html' =&gt; 'Amborovy Airport (Philibert Tsiranana Airport)',
        'lat' =&gt; '-0.666944',
        'lng' =&gt; '46.3517',
      ),
      1 =&gt; 
      array (
        'id' =&gt; '6160',
        'name' =&gt; 'Generalissimo Francisco de Miranda Airbase',
        'label' =&gt; 'Generalissimo Francisco de Miranda Airbase',
        'html' =&gt; 'Generalissimo Francisco de Miranda Airbase',
        'lat' =&gt; '0.485',
        'lng' =&gt; '-66.8436',
      ),
      2 =&gt; 
      array (
        'id' =&gt; '7808',
        'name' =&gt; 'Tirana International Airport',
        'label' =&gt; 'Tirana International Airport',
        'html' =&gt; 'Tirana International Airport',
        'lat' =&gt; '41.4150929722',
        'lng' =&gt; '19.7233001667',
      ),
      3 =&gt; 
      array (
        'id' =&gt; '20881',
        'name' =&gt; 'Tiranë Heliport',
        'label' =&gt; 'Tiranë Heliport',
        'html' =&gt; 'Tiranë Heliport',
        'lat' =&gt; 41.315865416667,
        'lng' =&gt; 19.888245972222,
      ),
      4 =&gt; 
      array (
        'id' =&gt; '5218',
        'name' =&gt; 'Abadan Airport',
        'label' =&gt; 'Abadan Airport',
        'html' =&gt; 'Abadan Airport',
        'lat' =&gt; '0.371111',
        'lng' =&gt; '48.2283',
      ),
      5 =&gt; 
      array (
        'id' =&gt; '5330',
        'name' =&gt; 'Lar Airport',
        'label' =&gt; 'Lar Airport',
        'html' =&gt; 'Lar Airport',
        'lat' =&gt; '0.673056',
        'lng' =&gt; '54.3814',
      ),
      6 =&gt; 
      array (
        'id' =&gt; '7808',
        'name' =&gt; 'Tirana International Airport',
        'label' =&gt; 'Tirana International Airport',
        'html' =&gt; 'Tirana International Airport',
        'lat' =&gt; '41.4150929722',
        'lng' =&gt; '19.7233001667',
      ),
      7 =&gt; 
      array (
        'id' =&gt; '20881',
        'name' =&gt; 'Tiranë Heliport',
        'label' =&gt; 'Tiranë Heliport',
        'html' =&gt; 'Tiranë Heliport',
        'lat' =&gt; 41.315865416667,
        'lng' =&gt; 19.888245972222,
      ),
      8 =&gt; 
      array (
        'id' =&gt; '5218',
        'name' =&gt; 'Abadan Airport',
        'label' =&gt; 'Abadan Airport',
        'html' =&gt; 'Abadan Airport',
        'lat' =&gt; '0.371111',
        'lng' =&gt; '48.2283',
      ),
      9 =&gt; 
      array (
        'id' =&gt; '5225',
        'name' =&gt; 'Ahvaz Airport',
        'label' =&gt; 'Ahvaz Airport',
        'html' =&gt; 'Ahvaz Airport',
        'lat' =&gt; '0.337431',
        'lng' =&gt; '48.762',
      ),
      10 =&gt; 
      array (
        'id' =&gt; '5242',
        'name' =&gt; 'Ardabil Airport',
        'label' =&gt; 'Ardabil Airport',
        'html' =&gt; 'Ardabil Airport',
        'lat' =&gt; '0.325556',
        'lng' =&gt; '48.4242',
      ),
      11 =&gt; 
      array (
        'id' =&gt; '5243',
        'name' =&gt; 'Asalouyeh Airport',
        'label' =&gt; 'Asalouyeh Airport',
        'html' =&gt; 'Asalouyeh Airport',
        'lat' =&gt; '0.481389',
        'lng' =&gt; '52.6153',
      ),
      12 =&gt; 
      array (
        'id' =&gt; '5251',
        'name' =&gt; 'Bandar Abbas International Airport',
        'label' =&gt; 'Bandar Abbas International Airport',
        'html' =&gt; 'Bandar Abbas International Airport',
        'lat' =&gt; '0.218056',
        'lng' =&gt; '56.3778',
      ),
      13 =&gt; 
      array (
        'id' =&gt; '5259',
        'name' =&gt; 'Birjand Airport',
        'label' =&gt; 'Birjand Airport',
        'html' =&gt; 'Birjand Airport',
        'lat' =&gt; '0.898056',
        'lng' =&gt; '59.2661',
      ),
      14 =&gt; 
      array (
        'id' =&gt; '5278',
        'name' =&gt; 'Dezful Airport',
        'label' =&gt; 'Dezful Airport',
        'html' =&gt; 'Dezful Airport',
        'lat' =&gt; '0.434444',
        'lng' =&gt; '48.3976',
      ),
      15 =&gt; 
      array (
        'id' =&gt; '5306',
        'name' =&gt; 'Jiroft Airport',
        'label' =&gt; 'Jiroft Airport',
        'html' =&gt; 'Jiroft Airport',
        'lat' =&gt; '0.726944',
        'lng' =&gt; '57.6703',
      ),
      16 =&gt; 
      array (
        'id' =&gt; '5326',
        'name' =&gt; 'Konarak Airport',
        'label' =&gt; 'Konarak Airport',
        'html' =&gt; 'Konarak Airport',
        'lat' =&gt; '0.443333',
        'lng' =&gt; '60.3819',
      ),
      17 =&gt; 
      array (
        'id' =&gt; '5330',
        'name' =&gt; 'Lar Airport',
        'label' =&gt; 'Lar Airport',
        'html' =&gt; 'Lar Airport',
        'lat' =&gt; '0.673056',
        'lng' =&gt; '54.3814',
      ),
      18 =&gt; 
      array (
        'id' =&gt; '5331',
        'name' =&gt; 'Lavan Airport',
        'label' =&gt; 'Lavan Airport',
        'html' =&gt; 'Lavan Airport',
        'lat' =&gt; '0.810278',
        'lng' =&gt; '53.3561',
      ),
      19 =&gt; 
      array (
        'id' =&gt; '5359',
        'name' =&gt; 'Parsabad-Moghan Airport',
        'label' =&gt; 'Parsabad-Moghan Airport',
        'html' =&gt; 'Parsabad-Moghan Airport',
        'lat' =&gt; '0.603606',
        'lng' =&gt; '47.8815',
      ),
      20 =&gt; 
      array (
        'id' =&gt; '5361',
        'name' =&gt; 'Persian Gulf Airport (Khalije Fars Airport)',
        'label' =&gt; 'Persian Gulf Airport (Khalije Fars Airport)',
        'html' =&gt; 'Persian Gulf Airport (Khalije Fars Airport)',
        'lat' =&gt; '0.379444',
        'lng' =&gt; '52.7375',
      ),
      21 =&gt; 
      array (
        'id' =&gt; '5393',
        'name' =&gt; 'Shahid Sadooghi Airport',
        'label' =&gt; 'Shahid Sadooghi Airport',
        'html' =&gt; 'Shahid Sadooghi Airport',
        'lat' =&gt; '0.905',
        'lng' =&gt; '54.2764',
      ),
      22 =&gt; 
      array (
        'id' =&gt; '5411',
        'name' =&gt; 'Tabriz International Airport',
        'label' =&gt; 'Tabriz International Airport',
        'html' =&gt; 'Tabriz International Airport',
        'lat' =&gt; '0.133889',
        'lng' =&gt; '46.235',
      ),
      23 =&gt; 
      array (
        'id' =&gt; '1416',
        'name' =&gt; 'Arrachart Airport',
        'label' =&gt; 'Arrachart Airport',
        'html' =&gt; 'Arrachart Airport',
        'lat' =&gt; '-0.349167',
        'lng' =&gt; '49.2917',
      ),
      24 =&gt; 
      array (
        'id' =&gt; '7808',
        'name' =&gt; 'Tirana International Airport',
        'label' =&gt; 'Tirana International Airport',
        'html' =&gt; 'Tirana International Airport',
        'lat' =&gt; '41.4150929722',
        'lng' =&gt; '19.7233001667',
      ),
      25 =&gt; 
      array (
        'id' =&gt; '20881',
        'name' =&gt; 'Tiranë Heliport',
        'label' =&gt; 'Tiranë Heliport',
        'html' =&gt; 'Tiranë Heliport',
        'lat' =&gt; 41.315865416667,
        'lng' =&gt; 19.888245972222,
      ),
    ),
    'html' =&gt; '&lt;div&gt;&lt;b&gt;Search Results for terms \'Iran\'&lt;/b&gt;  &lt;/div&gt;&lt;a class="map-link"  href="javascript:void(0);" onclick="toggleMapsSearch(\'name\');"&gt;4 results of Names with "Iran"&lt;/a&gt;&lt;div id="map-results-name" class="map-results-nubbin" style="display:none;"&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'1403\')"&gt;Amborovy Airport (Philibert Ts&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt;ana Airport)&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'6160\')"&gt;Generalissimo Francisco De M&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt;da Airbase&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'7808\')"&gt;T&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt;a International Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'20881\')"&gt;T&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt;ë Heliport&lt;/a&gt;&lt;/div&gt;&lt;a class="map-link" href="javascript:void(0);" onclick="toggleMapsSearch(\'city\');"&gt;4 results of Cities with "Iran"&lt;/a&gt;&lt;div id="map-results-city" class="map-results-nubbin" style="display:none;"&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5218\')"&gt;Abadan, &lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Abadan Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5330\')"&gt;Lar, &lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Lar Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'7808\')"&gt;T&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt;a : Tirana International Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'20881\')"&gt;T&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt;a : Tiranë Heliport&lt;/a&gt;&lt;/div&gt;&lt;a class="map-link" href="javascript:void(0);" onclick="toggleMapsSearch(\'country\');"&gt;15 results of Countries with "Iran"&lt;/a&gt;&lt;div id="map-results-country" class="map-results-nubbin" style="display:none;"&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5218\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Abadan Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5225\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Ahvaz Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5242\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Ardabil Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5243\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Asalouyeh Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5251\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Bandar Abbas International Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5259\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Birjand Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5278\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Dezful Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5306\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Jiroft Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5326\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Konarak Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5330\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Lar Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5331\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Lavan Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5359\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Parsabad-Moghan Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5361\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Persian Gulf Airport (Khalije Fars Airport)&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5393\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Shahid Sadooghi Airport&lt;/a&gt;&lt;a class="map-sub-links" href="javascript:mapClickHandler(\'5411\')"&gt;&lt;span Style="color:red; Font-weight:bold;"&gt;Iran&lt;/span&gt; : Tabriz International Airport&lt;/a&gt;&lt;/div&gt;',
  )
  </code></pre>
  
  <p>And here's what happens when I try to encode it in JSON using Zends_JSON class...</p>
  
  <pre><code>{"map":[{"id":"1403","name":"Amborovy Airport (Philibert Tsiranana Airport)","label":"Amborovy Airport (Philibert Tsiranana Airport)","html":"Amborovy Airport (Philibert Tsiranana Airport)","lat":"-0.666944","lng":"46.3517"},{"id":"6160","name":"Generalissimo Francisco de Miranda Airbase","label":"Generalissimo Francisco de Miranda Airbase","html":"Generalissimo Francisco de Miranda Airbase","lat":"0.485","lng":"-66.8436"},{"id":"7808","name":"Tirana International Airport","label":"Tirana International Airport","html":"Tirana International Airport","lat":"41.4150929722","lng":"19.7233001667"},{"id":"20881","name":null,"label":null,"html":null,"lat":41.315865416667,"lng":19.888245972222},{"id":"5218","name":"Abadan Airport","label":"Abadan Airport","html":"Abadan Airport","lat":"0.371111","lng":"48.2283"},{"id":"5330","name":"Lar Airport","label":"Lar Airport","html":"Lar Airport","lat":"0.673056","lng":"54.3814"},{"id":"7808","name":"Tirana International Airport","label":"Tirana International Airport","html":"Tirana International Airport","lat":"41.4150929722","lng":"19.7233001667"},{"id":"20881","name":null,"label":null,"html":null,"lat":41.315865416667,"lng":19.888245972222},{"id":"5218","name":"Abadan Airport","label":"Abadan Airport","html":"Abadan Airport","lat":"0.371111","lng":"48.2283"},{"id":"5225","name":"Ahvaz Airport","label":"Ahvaz Airport","html":"Ahvaz Airport","lat":"0.337431","lng":"48.762"},{"id":"5242","name":"Ardabil Airport","label":"Ardabil Airport","html":"Ardabil Airport","lat":"0.325556","lng":"48.4242"},{"id":"5243","name":"Asalouyeh Airport","label":"Asalouyeh Airport","html":"Asalouyeh Airport","lat":"0.481389","lng":"52.6153"},{"id":"5251","name":"Bandar Abbas International Airport","label":"Bandar Abbas International Airport","html":"Bandar Abbas International Airport","lat":"0.218056","lng":"56.3778"},{"id":"5259","name":"Birjand Airport","label":"Birjand Airport","html":"Birjand Airport","lat":"0.898056","lng":"59.2661"},{"id":"5278","name":"Dezful Airport","label":"Dezful Airport","html":"Dezful Airport","lat":"0.434444","lng":"48.3976"},{"id":"5306","name":"Jiroft Airport","label":"Jiroft Airport","html":"Jiroft Airport","lat":"0.726944","lng":"57.6703"},{"id":"5326","name":"Konarak Airport","label":"Konarak Airport","html":"Konarak Airport","lat":"0.443333","lng":"60.3819"},{"id":"5330","name":"Lar Airport","label":"Lar Airport","html":"Lar Airport","lat":"0.673056","lng":"54.3814"},{"id":"5331","name":"Lavan Airport","label":"Lavan Airport","html":"Lavan Airport","lat":"0.810278","lng":"53.3561"},{"id":"5359","name":"Parsabad-Moghan Airport","label":"Parsabad-Moghan Airport","html":"Parsabad-Moghan Airport","lat":"0.603606","lng":"47.8815"},{"id":"5361","name":"Persian Gulf Airport (Khalije Fars Airport)","label":"Persian Gulf Airport (Khalije Fars Airport)","html":"Persian Gulf Airport (Khalije Fars Airport)","lat":"0.379444","lng":"52.7375"},{"id":"5393","name":"Shahid Sadooghi Airport","label":"Shahid Sadooghi Airport","html":"Shahid Sadooghi Airport","lat":"0.905","lng":"54.2764"},{"id":"5411","name":"Tabriz International Airport","label":"Tabriz International Airport","html":"Tabriz International Airport","lat":"0.133889","lng":"46.235"},{"id":"1416","name":"Arrachart Airport","label":"Arrachart Airport","html":"Arrachart Airport","lat":"-0.349167","lng":"49.2917"},{"id":"7808","name":"Tirana International Airport","label":"Tirana International Airport","html":"Tirana International Airport","lat":"41.4150929722","lng":"19.7233001667"},{"id":"20881","name":null,"label":null,"html":null,"lat":41.315865416667,"lng":19.888245972222}],"html":null}
  </code></pre>
  
  <p>Notice at the end - the humongous clunk of HTML - GONE replaced by a null.... whats happening here :(</p>
  
  <hr>
  
  <p>EDIT</p>
  
  <p>After some investigation I found this error in my error logs:</p>
  
  <pre><code>PHP Warning:  json_encode() [&lt;a href='function.json-encode'&gt;function.json-encode&lt;/a&gt;]: Invalid UTF-8 sequence in argument in C:\wamp\www\fltdata\library\Zend\Json.php
  </code></pre>
  
  <p>I think it might have something to do with the problem I'm facing? How do I fix this?</p>
  
  <hr>
  
  <p>EDIT</p>
  
  <p>My version of Php is 5.2.9-2 - I doubt this is due to the issue which was in versions earlier than 5.2.7... help here guys please!!!</p>
  
  <hr>
  
  <p>EDIT</p>
  
  <p>Running the object through json_encode() returns the same result and I get the same error:</p>
  
  <pre><code>PHP Warning:  json_encode() [&lt;a href='function.json-encode'&gt;function.json-encode&lt;/a&gt;]: Invalid UTF-8 sequence in argument in...
  </code></pre>
  
  <p>I'm stumped here :(</p>
  
  <hr>
  
  <p>SOLUTION</p>
  
  <p>WOO HOOO!!!! I figured it out: I just run the html string variable through a utf8_encode function and then run the JSON encode function on it:</p>
  
  <p>$result['html'] =  utf8_encode($result['html']);</p>
  
  <p>And it works - Thanks everybody for all the help guys - I feel heavily confined by not being able to vote more than once for each of the posts here - you've all been a fanstastic help :D Thanks again!!!</p>