0

Hello I am new to the python world, and I am learning, I am currently developing a WebApp in Django and I am using ajax for sending requests, what happens is that in the view.py I get a JSON, from which I have not been able to extract the attributes individually to send to a SQL query, I have tried every possible way, I appreciate any help in advance.

def profesionales(request):
    body_unicode = request.body.decode('utf-8')
    received_json = json.loads(body_unicode)
    data = JsonResponse(received_json, safe=False)

    return data 

Data returns the following to me

{opcion: 2, fecha_ini: "2021-02-01", fecha_fin: "2021-02-08", profesional: "168", sede: "Modulo 7", grafico: "2"} 

This is the answer I get and I need to extract each of the values ​​of each key into a variable

1 Answer 1

1

You can interpret this as dict.

for key in received_json:
   print(key,received_json[key])
   # do your stuff here


but if it's always a object with same keys (fixed keys), you can access directly:

key_data = received_json[key]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.