擅长:python、mysql、java
<p>从URL获取数据,然后调用<code>json.loads</code></p>
<p><strong>Python3示例:</p>
<pre><code>import urllib.request, json
with urllib.request.urlopen("http://maps.googleapis.com/maps/api/geocode/json?address=google") as url:
data = json.loads(url.read().decode())
print(data)
</code></pre>
<p><strong>Python2示例:</p>
<pre><code>import urllib, json
url = "http://maps.googleapis.com/maps/api/geocode/json?address=google"
response = urllib.urlopen(url)
data = json.loads(response.read())
print data
</code></pre>
<p>输出结果如下:</p>
<pre><code>{
"results" : [
{
"address_components" : [
{
"long_name" : "Charleston and Huff",
"short_name" : "Charleston and Huff",
"types" : [ "establishment", "point_of_interest" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
...
</code></pre>