不建议自己用正则处理,基本所有的编程语言里都有json处理的库,比如在python中,可以这样做
import json
import urllib2
data = json.load(urllib2.urlopen("/users/defunkt"))
上面的代码 使用get请求github的api,当然也可以使用post方法,可以使用requests这个库,更加方便
结果
{u'public_repos': 101, u'site_admin': True, u'subscriptions_url': u'/users/defunkt/subscriptions', u'gravatar_id': u'b8dbb1987e8e5318584865f880036796', u'hireable': True, u'id': 2, u'followers_url': u'/users/defunkt/followers', u'following_url': u'/users/defunkt/following{/other_user}', u'blog': u'/', u'followers': 12921, u'location': u'San Francisco', u'type': u'User', u'email': u'chris@', u'bio': u'', u'gists_url': u'/users/defunkt/gists{/gist_id}', u'company': u'GitHub', u'events_url': u'/users/defunkt/events{/privacy}', u'html_url': u'/defunkt', u'updated_at': u'-12-22T08:59:46Z', u'received_events_url': u'/users/defunkt/received_events', u'starred_url': u'/users/defunkt/starred{/owner}{/repo}', u'public_gists': 284, u'name': u'Chris Wanstrath', u'organizations_url': u'/users/defunkt/orgs', u'url': u'/users/defunkt', u'created_at': u'-10-20T05:24:19Z', u'avatar_url': u'/avatar/b8dbb1987e8e5318584865f880036796?d=https%3A%2F%%2Fc81e728d9d4c2f636f067f89cc14862c.png&r=x', u'repos_url': u'/users/defunkt/repos', u'following': 208, u'login': u'defunkt'}
>>> data["login"]
u'defunkt'
>>>
如果使用requests模块
>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.post("/post", data=payload)
>>> print r.text
{
...
"form": {
"key2": "value2",
"key1": "value1"
},
...
}
顺便说下 这个网站可以用来测试,非常方便
如果觉得《python post 请求json文件_post 请求获取 json》对你有帮助,请点赞、收藏,并留下你的观点哦!