开发者

How do I request and process JSON with python?

开发者 https://www.devze.com 2022-12-30 04:20 出处:网络
I am开发者_开发问答 trying to send a GET request to a URL that I know returns data in the form of JSON using python.

I am开发者_开发问答 trying to send a GET request to a URL that I know returns data in the form of JSON using python.

I would like to know how to send this request to http://someurl/path/to/json, and how to parse it - preferably to a python dict.


For anything with requests to URLs you might want to check out requests. For JSON in particular:

>>> import requests
>>> r = requests.get('https://github.com/timeline.json')
>>> r.json()
[{u'repository': {u'open_issues': 0, u'url': 'https://github.com/...


Python's standard library has json and urllib2 modules.

import json
import urllib2

data = json.load(urllib2.urlopen('http://someurl/path/to/json'))
0

精彩评论

暂无评论...
验证码 换一张
取 消