json_encode():laravel中参数中的UTF-8序列无效

时间:2015-09-22 08:15:34

标签: php arrays json laravel utf-8

当我在laravel

中执行dd($ somevariable)时,我得到了以下结果
array:12 [
  0 => {#223
    +"jobinspt_post_questions_id": 117
    +"category": "Fascia & Gutter"
    +"question": "The F&G is complete"
    +"subquestion": null
    +"passed": null
    +"rectification": null
    +"catpassed": "N"
  }
  1 => {#224
    +"jobinspt_post_questions_id": 118
    +"category": "Fascia & Gutter"
    +"question": "Temporary props are in use"
    +"subquestion": null
    +"passed": null
    +"rectification": null
    +"catpassed": "N"
  }
  2 => {#225
    +"jobinspt_post_questions_id": 119
    +"category": "Fascia & Gutter"
    +"question": "The F&G is straight, level and undamaged"
    +"subquestion": null
    +"passed": null
    +"rectification": null
    +"catpassed": "N"
  }
  3 => {#226
    +"jobinspt_post_questions_id": 120
    +"category": "Fascia & Gutter"
    +"question": "F&G at correct height and distance from frame"
    +"subquestion": null
    +"passed": null
    +"rectification": null
    +"catpassed": "N"
  }
  4 => {#227
    +"jobinspt_post_questions_id": 121
    +"category": "Fascia & Gutter"
    +"question": "Dutch gables are cut neatly and level"
    +"subquestion": null
    +"passed": null
    +"rectification": null
    +"catpassed": "N"
  }
  5 => {#228
    +"jobinspt_post_questions_id": 122
    +"category": "Fascia & Gutter"
    +"question": "All rafter brackets are installed"
    +"subquestion": null
    +"passed": null
    +"rectification": null
    +"catpassed": "N"
  }
  6 => {#229
    +"jobinspt_post_questions_id": 123
    +"category": "Fascia & Gutter"
    +"question": "All barge gutters/ returns are installed"
    +"subquestion": null
    +"passed": null
    +"rectification": null
    +"catpassed": "N"
  }
  7 => {#230
    +"jobinspt_post_questions_id": 124
    +"category": "Fascia & Gutter"
    +"question": "Hips and jacks are propped"
    +"subquestion": null
    +"passed": null
    +"rectification": null
    +"catpassed": "N"
  }
  8 => {#231
    +"jobinspt_post_questions_id": 125
    +"category": "Fascia & Gutter"
    +"question": "Ext & Int corners are installed"
    +"subquestion": null
    +"passed": null
    +"rectification": null
    +"catpassed": "N"
  }
  9 => {#232
    +"jobinspt_post_questions_id": 126
    +"category": "Fascia & Gutter"
    +"question": "Rake downs/ laybacks/drag downs installed"
    +"subquestion": null
    +"passed": null
    +"rectification": null
    +"catpassed": "N"
  }
  10 => {#233
    +"jobinspt_post_questions_id": 127
    +"category": "Fascia & Gutter"
    +"question": b"Rivets – correct colour and number"
    +"subquestion": null
    +"passed": null
    +"rectification": null
    +"catpassed": "N"
  }
  11 => {#234
    +"jobinspt_post_questions_id": 128
    +"category": "Fascia & Gutter"
    +"question": "Downpipes pops or drops installed as per plan"
    +"subquestion": null
    +"passed": null
    +"rectification": null
    +"catpassed": "N"
  }

]

当我将此数组编码为json时,我收到以下错误

  

json_encode():参数

中的UTF-8序列无效

我不知道无效的utf8序列在哪里。请帮我看看这个阵列有什么问题

2 个答案:

答案 0 :(得分:1)

查看数组转储中的元素10:

CFStream

有一个'b'字符需要删除。

答案 1 :(得分:0)

如果你正在使用MYSQL那么试试这个

$con = mysqli_connect('localhost', 'my_user', 'my_password', 'test');
mysqli_set_charset($con, 'utf8');