#!/usr/bin/python
import os
import json
import urllib
import urllib2
url = "https://www.example.com"
parameters = {'resource': 'aaaa',
'apikey': '1111'}
data = urllib.urlencode(parameters)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
json_data = response.read()
with open("test.json") as json_file:
json_file.write(json_data)
print json_data
我看不到我再次使用json它是在json_data被使用之前。将json值打印到文件
你为什么从JSON文件首先加载的数据呢?为什么你在这里使用'json.load()'**。 – 2014-09-22 11:16:10
它不在文件中吗?我在这里错过了什么? – 2014-09-22 11:25:48
据推测,收到的JSON已经是有效的编码JSON。为什么不把它写入文件?无需在此编码或解码。 – 2014-09-22 11:32:11