gpt4 book ai didi

python - 重复的 Json 字符串打印

转载 作者:行者123 更新时间:2023-11-30 22:34:20 24 4
gpt4 key购买 nike

我有这个 Json:

 [{u'PrevDay': 0.00020307, u'Volume': 37185.350516, u'Last': 0.00022451, u'OpenSellOrders': 930, u'TimeStamp': u'2017-07-02T22:58:04.493', u'Bid': 0.00022306, u'Created': u'2015-07-31T00:50:47.11', u'OpenBuyOrders': 196, u'High': 0.00024999, u'MarketName': u'BTC-AEON', u'Low': 0.000198, u'Ask': 0.00023, u'BaseVolume': 8.15021286}, {u'PrevDay': 0.0009134, u'Volume': 92603.74600271, u'Last': 0.00096555, u'OpenSellOrders': 1998, u'TimeStamp': u'2017-07-02T22:58:04.867', u'Bid': 0.0009662, u'Created': u'2017-05-17T19:54:30.143', u'OpenBuyOrders': 422, u'High': 0.001, u'MarketName': u'BTC-ANT', u'Low': 0.00088022, u'Ask': 0.00098754, u'BaseVolume': 84.66436976}, {u'PrevDay': 0.00208098, u'Volume': 9427.31361715, u'Last': 0.00215844, u'OpenSellOrders': 917, u'TimeStamp': u'2017-07-02T22:58:04.07', u'Bid': 0.00215972, u'Created': u'2017-05-02T06:26:32.897', u'OpenBuyOrders': 230, u'High': 0.00224997, u'MarketName': u'BTC-APX', u'Low': 0.00205, u'Ask': 0.00223999, u'BaseVolume': 19.99655187}, 

我想在一行中为每个重复的字符串打印 MarketNameTimeStamp

我正在使用 Python,到目前为止我已经尝试过了:

market = data['MarketName']
time = data['TimeStamp']
print time, market

现在我也想打印其他字符串,但我不知道如何。

最佳答案

您可以使用循环...在本例中, for环形。循环旨在迭代数据序列。您的方向是正确的,您只需要添加一些内容即可:

full_data = [{u'PrevDay': 0.00020307, u'Volume': 37185.350516, u'Last': 0.00022451, u'OpenSellOrders': 930, u'TimeStamp': u'2017-07-02T22:58:04.493', u'Bid': 0.00022306, u'Created': u'2015-07-31T00:50:47.11', u'OpenBuyOrders': 196, u'High': 0.00024999, u'MarketName': u'BTC-AEON', u'Low': 0.000198, u'Ask': 0.00023, u'BaseVolume': 8.15021286}, {u'PrevDay': 0.0009134, u'Volume': 92603.74600271, u'Last': 0.00096555, u'OpenSellOrders': 1998, u'TimeStamp': u'2017-07-02T22:58:04.867', u'Bid': 0.0009662, u'Created': u'2017-05-17T19:54:30.143', u'OpenBuyOrders': 422, u'High': 0.001, u'MarketName': u'BTC-ANT', u'Low': 0.00088022, u'Ask': 0.00098754, u'BaseVolume': 84.66436976}, {u'PrevDay': 0.00208098, u'Volume': 9427.31361715, u'Last': 0.00215844, u'OpenSellOrders': 917, u'TimeStamp': u'2017-07-02T22:58:04.07', u'Bid': 0.00215972, u'Created': u'2017-05-02T06:26:32.897', u'OpenBuyOrders': 230, u'High': 0.00224997, u'MarketName': u'BTC-APX', u'Low': 0.00205, u'Ask': 0.00223999, u'BaseVolume': 19.99655187}]
for data in full_data:
market = data['MarketName']
time = data['TimeStamp']
print time, market

这给出:

2017-07-02T22:58:04.493 BTC-AEON
2017-07-02T22:58:04.867 BTC-ANT
2017-07-02T22:58:04.07 BTC-APX

关于python - 重复的 Json 字符串打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44876006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com