我在带有application/json
的java中将HttpPost
发送到使用Django的服务器。
我正按照此处所述执行传输:JSON POST request parsing in PHP
如何创建接收此json数据的页面?
答案 0 :(得分:7)
您可以通过request.raw_post_data
data=simplejson.loads( request.raw_post_data )
答案 1 :(得分:1)
your views中的request
变量包含属性request.POST
,其中包含帖子数据。这是(在技术上,就像一个字典)。您还想查看python标准库中的json module
最后我想你会想要像
这样的东西def my_view(request):
# error checking omitted here, e.g. what if nothing is posted
# or the json is invalid etc.
posted_json = request.POST['my_json_variable']
my_dict = json.loads(posted_json)
# do something with the data