python - Parsing Json data sent by android clinet using "post" request in django view -


I am trying to loop around the JSN data sent by my Android client. I used the code below but it is not working for me Any possible error I am doing ... ???? Try: x101 = json.loads (request.body) x101 for data x101 print: print data ['apip' aetected = data ['esetected'] ['api_json' ] Credential = Data ['Credential'] D1 = Data ['D1'] D2 = Data ['D2'] D3 = Data ['D3'] angle = Data ['angle'] Status = Data ['Position'] operator = data ['operator'] location = data ['location'] print asset_code, credential, d1, d2, d3, angle, position, operator, location v = verifier (asset_code = Asset_code, Scan_time = datetime.datetime.now (), crede Shell = Credential, D1 = D1, D2 = D2, D3 = D3, angle = angle, position = position, operator = operator, location

error detection :

  Typewriter: string index must be an integer  

< P> In a dictionary, while retaining its Jason decode, iterates through the key of the dictionary for the data in x 101 so the data ['D1 '] will give you type error See, "string indexes must be an integer."

Since you did not actually tell the data structure really, we can only guess, but you probably have x 101.values () for data through values ​​ again. .

In any case, you should definitely try to remove it / except that the print is "no" for some reason there are mistakes, and to silence them will prevent you from debugging properly , As we see here.

Edit

The x101 is just a single dict. You say that there will often be more than one word, but it probably can not work like this: The only way to many rules is to put them inside a list (i.e. a JSON array) and if so, then Always in the list, even if there is only one. Then your structure should be:

  [["angle": "10", "asset_code": "XPS1020", "credential": "wqw2323ds2", "d1": "1", "D2": "2", "D3": "3", "Location": "Bangalore", "Operator": "Pradeep", "Status": "1"}]  

Then your code will work as much, whether there is a single word or a lot.


Comments