[英]How can I use python to filter the json with AWS list pricing API?
我想過濾OperatinSystem是linux的json,但我有一些問題,json中的部分
'' : {
我不知道字典是怎么表示的,
"DQ578CGN99KG6ECF" : {
我怎么用通配符表示它,任何人都可以幫助我。
import json
import urllib2
response=urllib2.urlopen('https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json')
url=response.read()
urlj=json.loads(url)
filterx=[x for x in urlj if x['??']['??']["attributes"]["operatingSystem"] == 'linux']
我不確定通配符表示形式。 我會調查一下,然后再回覆您。 同時,我之前已經使用過此json,所以我可以告訴您如何訪問所需的信息。 您可以通過以下方式獲取所需信息:
for each_product in urlx['products']:
if urlx['products'][each_product]['attributes']['operatingSystem']=="linux":
#your code here
如果您需要json中的價格信息,則需要獲取產品代碼字符串,並查看priceDimensions字段。 查看示例json並相應地進行編碼。 https://aws.amazon.com/blogs/aws/new-aws-price-list-api/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.