Convert JSON data to dictionaries in jquery

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.