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