Get json data via url and use in python (simplejson)

后端 未结 3 880
不思量自难忘°
不思量自难忘° 2021-01-30 02:38

I imagine this must have a simple answer, but I am struggling: I want to take a url (which outputs json) and get the data in a usable dictionary in python. I am stuck on the la

3条回答
  •  隐瞒了意图╮
    2021-01-30 03:00

    The first line reads the entire file. The second line then tries to read more from the file, but there's nothing left:

    >>> f.read()             # this works
    blah blah blah
    >>> simplejson.load(f)
    

    Either just omit the f.read() line, or save the value from read, and use it in loads:

    json = f.read()
    simplejson.loads(json)
    

提交回复
热议问题