python 学习之调用web api

import urllib
import json
url = 'http://xxx.xxx.xxx.xxx:8888/xxxx-api/customer/qq/channels'
def get_data():
    response = urllib.urlopen(url).read()
    json_array = json.loads(response)
    channel = {}
    for json_map in json_array:
        channel[json_map['code']] = json_map['name']
    return channel;
if __name__ == '__main__':
    clist = get_data()
    for key in clist.keys():
        print("%s %s") % (key, clist[key])

你可能感兴趣的:(python)