我创建了一个表成员,其中包含一个需要存储日语的字段“名称”。我使用网络服务访问表数据。下面是代码,
from django.http import HttpResponse
from rest_framework.renderers import JSONRenderer
class JSONResponse(HttpResponse):
"""
An HttpResponse that renders it's content into JSON.
"""
def __init__(self, data, **kwargs):
content = JSONRenderer().render(data)
kwargs['content_type'] = 'application/json'
super(JSONResponse, self).__init__(content, **kwargs)
from rest_framework import serializers
class MemberSerializer(serializers.ModelSerializer):
class Meta:
model = Member
fields = ('member_id', 'name', 'homepage', 'map')
def restore_object(self, attrs, instance=None):
"""
Create or update a new Member instance, given a dictionary
of deserialized field values.
Note that if we don't define this method, then deserializing
data will simply return a dictionary of items.
"""
if instance:
# Update existing instance
instance.member_id = attrs.get('member_id', instance.member_id)
instance.name = attrs.get('name', instance.name)
instance.homepage = attrs.get('homepage', instance.homepage)
instance.map = attrs.get('map', instance.map)
return instance
# Create new instance
return Member(**attrs)
//snapshot code
serializer = MemberSerializer(member)
return JSONResponse(serializer.data)
'name' 值显示为 unicode ,{"name": "\u691c\u8a3a\u3092\u4e88\u7d04\u3059\u308b"}。怎么转成日文?