我正在向api发送json数据,但是从android设备获取unicode json数据

问题描述:

我的数据 - :

{"op":"merge","merge_bcards_ids":{"data":[216,217]},"target_bacard_id":226}

在查看文件中我收到了json列表数据请求。 data [merge_bcards_ids]: -

In view file I am getting json list data request.data["merge_bcards_ids"] :-

[258, 259] <type 'list'> which is showing correct.

但是,当从外部设备拨打这个api时,然后: -

But when this api call from external device then :-

[257,258] <type 'unicode'>

所以我想要列表而不是unicode。请帮助我。

So I want list instead of unicode. Please help me out.

我的观点是: -

class BusinessViewSet(viewsets.ModelViewSet):
   queryset = BusinessCard.objects.all()
   serializer_class = BusinessCardSerializer

   def create(self, request):
       try:
          op = request.data["op"]
       except:             
          op = None

       if op == 'merge':
              try:
                 merge_bcards_ids = request.data["merge_bcards_ids"]
                 target_bacard_id = request.data["target_bacard_id"]
              except:
                 merge_bcards_ids = None
                 target_bacard_id = None
              print merge_bcards_ids   
              print merge_bcards_ids.__class__


确保您在提交请求时使用application / json内容类型。

Make sure you are using the "application/json" content type when submitting your request.