pareshm pareshm - 9 months ago 58
Python Question

Iterate through list passed as **kwargs in cheerypy python

Hi I am new to cheerypy and python

I am passing list of objects



to the Post request

def POST(self,*args, **kwargs):
print abc #output -[{"id":"01","name":"abc"},{"id":"02","name":"abcd"}]
for device in abc:
print device #its printing [,{,",i,d...

i want it to print complete object on Iteration


so can any one please help me how to achieve it.

Answer Source

The post data is being received as a JSON object which is a string. You need to convert it to a Python object first, in order to iterate over your data as a list of dictionaries and not as a string:

import json

abc = kwargs['deviceArr']
abc = json.loads(abc)