RSS

10 lines of code: using json in python

26 Mar

1.  import httplib,json
2.  url =
‘www.yupoo.com’
3.  path =
‘/api/json/api_key=d74aad0331494be468c07f47987b099b&method=yupoo.photos.licenses.getInfo’
4.  conn = httplib.HTTPConnection(url)
5.  conn.request(“GET”, path)
6.  response = conn.getresponse()
7.  if response.status == 200 :
8.      result = response.read()
9.      result2 = json.loads(result)
10.     print result2[‘stat’]

If the above code is saved as Demo.py, in Cmd window, run this: “python Demo.py

image

Download Demo.py.

Advertisements
 
Leave a comment

Posted by on March 26, 2012 in Programming

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: