0

I have this code , in this code i get a json object from a url(ajax) and i need to get internal data, this is my code:

url = URL_BASE9


req = requests.get(url)
statusCode = req.status_code
if statusCode == 200:

html = BeautifulSoup(req.text, "html.parser")
#print(html)

and this is my result

`{'FiltroFechaInicio': '/Date(-62135586000000)/', 'Pagina': 1, 'ListHechos': 
 [{'contenido': '<div class="ExternalClass3DB02CFE22F84F3F998EBEA913E5A79B">
 <div><a 
 href="/Noticiascibe/hechos%20esenciales/NAVIERA/hes_2017060105740.pdf">
 hes_2017
 060105740.pdf</a></div></div>', 'Activo': None, 'FechaString': '15-06-
 2017', 
 'TipoAdjunto': None, 'UrlAdjunto': 
 '/Noticiascibe/hechos%20esenciales/NAVIERA/hes_2017060105740.pdf', 
 'Descripcion': None, 'UrlImagen': None, 'ClaseIconoAdjunto': 
 'iconoDescargaPDF', 'Fecha': '/Date(1497566727000)/'}`

how do get the content of data, thanks and have nice day

Marcelo Rojas
  • 15
  • 1
  • 3
  • 2
    Possible duplicate of [Parsing values from a JSON file using Python?](https://stackoverflow.com/questions/2835559/parsing-values-from-a-json-file-using-python) – Will Da Silva Jun 16 '17 at 16:20

2 Answers2

1

There's no such thing as a "JSON object", you're talking about a JSON string.

To convert a JSON string into an object you can use json.loads(json_str) from the json module (docs).

example:

import json
json_str = '{ "FiltroFechaInicio": "/Date(-62135586000000)/" }'
my_obj = json.loads( json_str )

By the way, the JSON string you posted is both invalid and incomplete. Valid JSON must have keys and strings enclosed in double quotes.

Mike Scotty
  • 10,530
  • 5
  • 38
  • 50
  • sorry, my english is not perfect, i need extract the data string of json because after extract the data i can insert the data in a database – Marcelo Rojas Jun 16 '17 at 16:28
0

It is the same as with dictionary, you have a keys and values for every key

  my_dict = {
    'key1': 'value1',
    'key2': 'value2',
    'key3': 'value3'
    }
my_dict['key1']

# Out: 'value1'
a.kozubenko
  • 1,030
  • 3
  • 15
  • 24