我正在向api发送json数据,但是从android设备获取unicode json数据 [英] I am sending json data to api but getting unicode json data whe api call from android device
本文介绍了我正在向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.
这篇关于我正在向api发送json数据,但是从android设备获取unicode json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文