最近我開始深入Python,想知道是否可以發佈一些關於如何對JSON字符串進行編碼的代碼,將它作爲HTTP請求發送到URL並解析響應。Python JSON調用
下面是一些代碼,我一直在玩弄:
import os
import json
if os.name == 'nt':
def clear_console():
subprocess.call("cls", shell=True)
return
else:
def clear_console():
subprocess.call("clear", shell=True)
return
def login_call(username, password):
choice = 0
while int(choice) not in range(1,2):
clear_console()
print ('')
print (' Json Calls - Menu')
choice = input('''
1. Login.
Enter Option: ''')
print ('')
choice = int(choice)
if choice == 1:
login_call(username, password)
代碼中沒有顯示,即使在這樣的一個嘗試。 – 2012-07-30 22:08:23
我想你可以使用'requests' http://docs.python-requests.org/en/latest/index.html來發送和接收它。我不確定'request'如何處理髮送'JSON'。 – TankorSmash 2012-07-30 22:12:22