title: jQuery jqGrid error: Syntax Error: Unexpected token I in JSON at position 0
body: <p>I see this as a &quot;popular&quot; error here on SO, but I'm more trying to figure out how to trap what is actually going on in this jQuery-specific case.  This is code for a client site that used to work but now that I've upgraded him to PHP 7.x, it seems to be broken for some reason.</p>
  <p>It's a straight PHP program containing jQuery data grids allowing my client to maintain his site data.  Pretty simple stuff and I'm perplexed as to why or what is breaking it.</p>
  <p>The following is the definition of the data grid itself:</p>
  <pre><code>jQuery(&quot;#list2&quot;).jqGrid({ url:'?location=locations&amp;action=get',
        datatype: &quot;json&quot;,
        colNames:['id','Activity', 'Name','Shortname', 'Active],
        colModel:[
            {name:'locationid',index:'fas_locationid', width:25,editable:false,editoptions:{size:10}},
            {name:'Activity',index:'abc_activityid', width:90,editable:true,edittype:&quot;select&quot;,editoptions:{dataUrl:'?location=sports&amp;action=get&amp;oper=select',value:sports},formatter:'select'},
            {name:'name',index:'name', width:200,editable:true,editoptions:{size:50},editrules:{required:true}},
  etc....
           ],
        rowNum:40, rowList:[40,80,120],pager: '#pager2',sortname: 'locationid',
        viewrecords: true, height: 600,width:1020,  
        loadComplete: function () {
          alert(&quot;OK&quot;); },   
      loadError: function (jqXHR, textStatus, errorThrown) {
          //var obj = jQuery.parseJSON(jqXHR.responseText);
          alert('HTTP status code: ' + jqXHR.status + '\n' +
                'textStatus: ' + textStatus + '\n' +
                'errorThrown: ' + errorThrown);
          alert('HTTP message body (jqXHR.responseText): ' + '\n' + jqXHR.responseText);
      },
        sortorder: &quot;asc&quot;,
        editurl:&quot;?location=locations&amp;action=edit&quot;,
        caption:&quot;Locations&quot; });
  </code></pre>
  <p>To debug, I added the 'loadError' and 'loadComplete' callbacks above and the load error callback throws the following:</p>
  <pre><code>&quot;HTTP status code: 200
  textStatus: parseerror
  errorThrown: Syntax Error: Unexpected token 'I' in JSON at position 0&quot;
  </code></pre>
  <p>I've debugged the code that prepares the data for the grid and it appears correct to me, but obviously, there's some message or something that starts with 'I' that is getting appended to the return set somehow, and I need some help getting the entire text perhaps. Any hints that you might have on how to get to that are welcomed.</p>
  <p>The code that prepares the data for the grid is also straightforward, this is the relevant bit of it that prepares and returns the data to the grid:</p>
  <pre><code>$i =0;
  foreach ($Locations as $Location) {
   
      $this-&gt;response-&gt;rows[$i]['id']= $Location-&gt;get('locationid');
      $this-&gt;response-&gt;rows[$i]['cell']=array($Location-&gt;get('locationid'),$Location-&gt;get('activityid'), etc......
  );
     $i++; 
  }
  $jsData = json_encode($this-&gt;response);
  $ecode = json_last_error_msg();  // I put this in to trap any json error and it says &quot;No Errors&quot;.
  echo $jsData;
  </code></pre>
  <p>Does anyone have any suggestions on how to trap what is going on?  If there was a JSON encoding error, I would expect the last line of code to tell me if there was a JSON problem, but it tells me nothing.</p>
  <p>Any suggestions for how to debug or another approach to take are welcome!  As I wrote earlier, all this code is pretty 'ancient' but has worked before.
  thank you!</p>
  <p>[edit:  As requested, here is the full dump of $this-&gt;response....</p>
  <p>{&quot;page&quot;:&quot;1&quot;,&quot;total&quot;:1,&quot;records&quot;:35,&quot;rows&quot;:[{&quot;id&quot;:2,&quot;cell&quot;:[2,1,etc.... (removed the rest because it is my client's data)</p>
  <p>As requested, i looked at the response in Chrome dev tools and found the following under the response (ignore the double quotes):</p>
  <pre><code>&quot;I&lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  Creating default object from empty value in &lt;b&gt;/Applications/MAMP/htdocs/myproj/public_html/manager/controllers/manager.class.php&lt;/b&gt; on line &lt;b&gt;2297&lt;/b&gt;&lt;br /&gt;&quot;
  </code></pre>
  <p>and the next line of the response is exactly what i pasted in above.</p>
  <p>Again, notice the &quot;I&quot; at the very beginning of the response.  I have NO idea where that might be coming from or how to go about finding it.  In the past, i've seen an &quot;O&quot; in that position, but that's because what was being returned was unknowingly an &quot;O&quot;bject (as in &quot;Object: object&quot;).  I assume this rogue character is causing my error, but i can't prove it.  And i don't know where it is coming from, based on the above, i think it's the first character of a message, but no idea how to get at it.</p>
  <p>[EDIT]
  I never did figure this out.  I did isolate the issue to the 'I' character being written to the response text from jquery.min.js during the creation of the grid itself, but i never did figure out how or why jquery was doing that.  However, i got my client to go another direction, so my need to solve this issue has ceased.  Thanks to those who tried to help me out though, much appreciated!
  [END EDIT]</p>