Further depth with python

已查看 126 次
跳至第一个未读帖子

Wrayman

未读,
2016年10月29日 19:41:442016/10/29
收件人 Octopart API
This is working not a problem.

But I can't get any deeper into the JSON

Is there a guide for accessing/addressing all the arrays in the returned JSON?

for example, I have gotten this far: print item['offers'][2]['sku'], but I seem to be stuck, can get into the prices because I don't know how to access the arrays properly.

If someone could point out the fields and the way to access them, it would save a lot of time.



import json
import urllib

url = 'http://octopart.com/api/v3/parts/match?'
url += '&queries=[{"mpn":"SN74S74N"}]'
url += '&apikey=REPLACE_ME'

data = urllib.urlopen(url).read()
response = json.loads(data)

# print request time (in milliseconds)
print response['msec']

# print mpn's
for result in response['results']:
    for item in result['items']:
        print item['mpn']
回复全部
回复作者
转发
0 个新帖子