JSON编码为MySQL

时间:2022-02-26 16:52:31

I have a problem regarding encoding.

我有一个关于编码的问题。

I created a MySQL 5.5 DB containing some text. I also create a Java Webservice which creates JSON which is read by an Android application.

我创建了一个包含一些文本的MySQL 5.5 DB。我还创建了一个Java web服务,它创建由Android应用程序读取的JSON。

I have stored text in the DB and it looks good, for example :

我已经在DB中存储了文本,它看起来不错,例如:

verwarm de oven voor op 210°C

verwarm de烤箱voor op 210°C

But when I check the JSON in the browser it looks like this (and also in my Android app)

但当我在浏览器中查看JSON时它会是这样的(在我的安卓应用中也是这样)

{"gerechtId":"6","id":"13","laatsteUpdate":"2013-02-14T15:53:42+01:00","text":"verwarm de oven voor op 210°C","titel":"oven voorverwarmen","volgNr":"1"}

{“gerechtId”:“6”,“id”:“13”、“laatsteUpdate”:“2013 - 02 - 14 - t15:53:42 + 01:00”、“文本”:“verwarm de烤箱voor op 210°C”,“标题”:“烤箱voorverwarmen”、“volgNr”:“1”}

As you can see, the temperature is showing characters I don't like ;-)

正如你看到的,温度显示的字符我不喜欢;

How can I avoid this ?

我怎样才能避免这种情况呢?

I'm using Hibernate 3 for reading the db. Here is my persistence.xml :

我使用Hibernate 3来读取db。这是我的坚持。xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence     http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd ">
    <persistence-unit name="LENGO" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider> 
    <properties>

        <property name="hibernate.archive.autodetection" value="class, hbm"/>
        <property name="hibernate.connection.url" value="jdbc:mysql://62.213.197.17/lengotoo_autikoken?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>

    </properties>
</persistence-unit>
</persistence>

1 个解决方案

#1


0  

I solved the question by doing this :

我通过这样做来解决这个问题:

@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")

instead of

而不是

@Produces(MediaType.APPLICATION_JSON)

in the resources of my webservice.

在我的网络服务资源中。

#1


0  

I solved the question by doing this :

我通过这样做来解决这个问题:

@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")

instead of

而不是

@Produces(MediaType.APPLICATION_JSON)

in the resources of my webservice.

在我的网络服务资源中。