Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Json请求url_Python_Json - Fatal编程技术网

Python Json请求url

Python Json请求url,python,json,Python,Json,我使用JSON和请求从URL获取一些阈值的价格 如何获得特定符号的价格,例如Z1的价格 以下是url的输出: [{"symbol":"E1","price":"89"},{"symbol":"E2","price":"87"},{"symbol":”Z1","price":"73"},{"symbol":"D4","price":"47"}] 我的代码如下: def prices(): priceTick = requests.get('https://www.examples/pri

我使用JSON和请求从URL获取一些阈值的价格

如何获得特定符号的价格,例如Z1的价格

以下是url的输出:

[{"symbol":"E1","price":"89"},{"symbol":"E2","price":"87"},{"symbol":”Z1","price":"73"},{"symbol":"D4","price":"47"}]
我的代码如下:

def prices():
    priceTick = requests.get('https://www.examples/prices')
    return priceTick.json()

我会将其转换为更可用的数据结构,以提供快速查找—字典:

price_ticks = {item["symbol"]: item["price"] for item in prices()}
print(price_ticks["Z1"])

当然,这假设每个符号都有一个单一的price-1-1映射。

我会将其转换为更可用的数据结构,以提供快速查找—字典:

price_ticks = {item["symbol"]: item["price"] for item in prices()}
print(price_ticks["Z1"])

当然,这是假设每个符号都有一个单一的价格-1对1映射。

您可能会遇到问题,因为Z1之前有一个卷曲的报价-将其更改为标准”,这很容易导致问题!

您也可能会遇到问题,因为Z1之前有一个卷曲的报价-将其更改为标准“,这很容易引起问题

是的,它使用1:1映射。谢谢,它现在按我的要求工作。是的,它使用1:1映射。谢谢,现在我想怎么做就怎么做。当然,如果我是他们,我会按照你说的那样使用,但不幸的是我无法更改。当然,如果我是他们,我会按照你说的那样使用,但不幸的是我无法更改。