重复的Json字符串打印

时间:2017-07-02 23:19:57

标签: python json string

我有这个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}, 

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

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

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

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

1 个答案:

答案 0 :(得分:3)

您可以使用循环...在这种情况下,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