My json content is like this:
{
"type":"user",
"ifor":[
{
"id":001,
"name:"lison"
},
{
"id":002,
"name":"wei"
}
]
}
In JS, I use the ajax method of jquery to pass it, and write it like this:
$.ajax("url",{
type:"post",
data:{
type:"user",
ifor: [
{
id:001,
name:"lison"
},
{
id:002,
name:"wei"
}
]
},
success:function(){}
})
Mine is python3.6, and django is 1.11.1. How should I receive it in views.py in django? I checked a lot online, some said json.loads(request.body), some said simplejson.loads(request.raw_post_data), but they all seemed to have problems. Could you please tell me how to receive and parse it
Front-end ajax:
Backend value:
You must first determine what the content you pass to the backend looks like. It cannot be directly
json.loads
Assume that the source code of the view corresponding method is as follows
Only the
json
format that conforms to'{"aa":"xxx"...}'
can be recognized and deserialized byjson.loads
. If the result returned is not like thisjson
Format, then you need to adjust the front-endajax
to be able to construct such data. Specifically, you can construct it throughdataType: json
or through string splicing. For details, you can Google it yourself:ajax passes json data