json.Parse特殊字符并变为null

Error:

data[i].last_name is null

I check the result from php and which has "Beñas" which triggers the null value.

 xhr.queue({
    url: 'controller/agents_handler.php',
    data: {load_request: 'top_earners'},
    type: 'POST',
    success: function(data) {
        var data = JSON.parse(data);
        var topEarnersDiv = $('.top_earners_container ul');
        var str = "";
        for ( i in data) {
             str += '<p class="lastname boldthis">'+data[i].last_name.substr(0,8)+'</p>';
        }
   topEarnersDiv.html(str);
   }

Sample response:

 {
  "user_id": "12345",
  "user_name": "johnb",
  "first_name": "john",
  "last_name": null
  }

from php response:

it has Beñas value which becomes null

PHP:

  $sql = "SELECT * FROM students WHERE x= active";
  db::query($sql);
  $mtd_list = array();
  while ($rows = db::fetch_assoc()) :
       $mtd_list[] = $rows;
   endwhile;

  return $mtd_list;

It should be an enconding error, if you change change the php code, you should use utf8_encode() to parse every string in that object.