【问题标题】:json_encode(): Invalid UTF-8 sequence in argument in laraveljson_encode():laravel 中的参数中的 UTF-8 序列无效
【发布时间】:2015-09-22 08:15:34
【问题描述】:

当我在 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 序列在哪里。请帮我找出这个数组有什么问题

【问题讨论】:

    标签: php arrays json laravel utf-8


    【解决方案1】:

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

    +"question": b"Rivets – correct colour and number"
    

    有一个“b”字符需要删除。

    【讨论】:

      【解决方案2】:

      如果你使用的是 MYSQL,那么试试这个

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多