Problem with JSON - Python3.4

2

I'm working with the API of BuscaPé to be able to remove information from some products of the site, the problem is that I can not manipulate one of the values of the json returned. Here are some results I could get:

resp = buscape.find_product_list(keyword='jogos', format='json') # Fazendo a consulta

resp.keys() # Retornou: 'dict_keys(['data', 'code'])'

type(resp['code']) # Retornou: '<\class 'int>'

type(resp['data']) # Retornou: '<\class 'bytes>'

As you can see, when I checked the type of resp ['data'] (field that holds the values I need) python returned me the value 'class bytes', so I can even convert this value to string , the problem is that it would be laborious to look up every information I need that way.

I've tried to do the dump as follows:

import json

json.dumps(resp)

But the interpreter returns the following error: is not JSON serializable .

Since json is very large, I left the code hosted in my pastebin so that you have a better idea of the problem I am facing.

    
asked by anonymous 23.09.2015 / 00:39

1 answer

0

As far as I can understand, you only need to use the .decode method to convert from bytes to unicode. See if you can do this conversion as follows:

import json

json.dumps(resp['data'].decode('utf-8'))
    
16.08.2018 / 01:11