json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8 [英] json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT

查看:38
本文介绍了json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 mssql 的数据库查询有一个恼人的问题.如果结果包含像德语ä"这样的特殊字符,我将无法使用 json_encode 正确地将结果作为 json 获取.

I have an annoying problem with a database query to mssql. If the result contains special characters like the german 'ä', I cannot use json_encode to get the result as json correctly.

json_last_error 返回 5 等于 JSON_ERROR_UTF8.我猜数据库不会返回 UTF-8 编码的值.数据库集合是*Latin1_General_CI_AS*,受影响的列是varchars.

json_last_error return 5 which is equal to JSON_ERROR_UTF8. I guess the database does not return the values as UTF-8 encoded. The database collection is *Latin1_General_CI_AS* and the affected columns are varchars.

php mssql.charset 配置没有效果.

The php mssql.charset configuration has no effect.

我读到 mysql 用户可以使用 mysql_query('SET CHARACTER SET utf8'); 正确编码返回值.我该怎么做才能正确获取 mssql 的值?

I read that mysql users could use mysql_query('SET CHARACTER SET utf8'); to encode the return values correctly. What can I do, to get the values correctly for mssql?

提示 - 我无法更改数据库中的任何内容.

推荐答案

在 JSON 编码之前,在字符串周围使用 utf8_encode().

Before you JSON encode, use utf8_encode() around the string.

这篇关于json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆