B
B
beduin012018-04-28 11:25:03
Python
beduin01, 2018-04-28 11:25:03

How to remove block from Json response?

myrequest = json.loads(x)
r = requests.post(url, json=myrequest)
result = r.json() #

I get a response like this:
[{u'aa': 11, u'price': {u'max':11, u'min': 4}}]
I need to throw out the price key from the answer, but the problem is that the following code swears that it cannot work with Unicode dictionaries, so you need to either make the dictionary non-Unicode, or understand it as an unnecessary block, otherwise throw it out :
for e in result[0]:
 	print(e)
 	if 'price' in e:
 		del e['price']

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Demidov, 2018-04-28
@beduin01

Why loop through the dictionary? ( you have a dictionary, not a list) you can justresult[0]

if 'price' in result[0].keys():
    del result[0]['price]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question