Python Django REST Framework 2中unicode键的反序列化

Python Django REST Framework 2中unicode键的反序列化,python,json,django,unicode,django-rest-framework,Python,Json,Django,Unicode,Django Rest Framework,我得到了包含以下内容的json文件: [ { "id": "201020102", "lab_name": "мурмур", "sex": "onto", "species": "onto", "age": "24 pontakleęfmnds", "strain": "onto", "desease": "onto", "comment": "some string" } ] 我

我得到了包含以下内容的json文件:

[
    {
      "id": "201020102",
      "lab_name": "мурмур",
      "sex": "onto",
      "species": "onto",
      "age": "24 pontakleęfmnds",
      "strain": "onto",
      "desease": "onto",
      "comment": "some string"
    }
]
我已经为它编写了序列化程序:

class SpecimenSerializer(serializers.Serializer):
    id = serializers.CharField()
    lab_name = serializers.CharField()
    sex = serializers.CharField()
    age = serializers.CharField()
    species = serializers.CharField()

    def restore_object(self, attrs, instance=None):
        if instance:
            # TODO make it mutable
            return instance

        return m.Entity.objects.create(lab_name=self.lab_name)
我正试图像这样反序列化我的json:

testJson = json.load(open("data/specimens.json"))
specimenSerializer = SpecimenSerializer(data=testJson[0])

问题是,我没有看到specimenSerializer.data中的字段填充json文件中的值。我认为它与unicode有关。在我的例子中,我可以保证json的键始终是ascii,但值可以是unicode

在访问
serializer.data
之前,您是否调用了
serializer.is\u valid()
?请参阅@SamRad DRF 2中的验证部分,该部分没有该限制(DRF 3会触发警告),尽管我仍然建议这样做。