First, the JSON data in the foreground page is
var recipe = {}; recipe[$ ("#name"). Val (); recipe[$ ("#age"). Val (); recipe[$ ("#sex"). Val (); recipe["{' Name ': ' A ', ' value ': ' B '}";
Using the Ajax post for transmission
$. Ajax ({ type:"post","JSON","/doctor/recipe/add/", Data:recipe, function (Data) {alert ("Success") }});
Get in Django View
The data in the Request.body is
<querydict: {u ' medicine ': [u ' age ': [u ' name ': [u 'sex ': [u ' 1 ']}>
You can find that the data under medicine is a string, but it is unciode format
"POST": Recipe_json = Request. post[' medicine '///First the data obtained here is Unicode format recipe = Recipe_json.encode ("UTF8")//convert it to strprint Recipeeval (recipe)//Use the Eval method to convert to dictionary eval (recipe)print recipe_dict[' name ']return HttpResponse (Json.dumps (True))
Convert JSON data to dictionaries in jquery