I次のコードは、持っている:あなたが見たよう解析コード
[
{
"LastTradePrice": "73.39",
"LastTradeWithCurrency": "€73.39",
"LastTradeDateTime": "2016-05-13T19:57:30Z",
"LastTradeDateTimeLong": "May 13, 7:57PM GMT+2",
"ID": "10224532",
"Index": "FRA",
"StockSymbol": "BMW",
"LastTradeTime": "7:57PM GMT+2"
}
]
<class 'str'>
<class 'list'>
[{'LastTradePrice': '73.39', 'LastTradeWithCurrency': '€73.39', 'LastTradeDateTimeLong': 'May 13, 7:57PM GMT+2', 'LastTradeDateTime': '2016-05-13T19:57:30Z', 'ID': '10224532', 'Index': 'FRA', 'StockSymbol': 'BMW', 'LastTradeTime': '7:57PM GMT+2'}]
test
Traceback (most recent call last):
line 11, in <module>
print((a)["Index"])
TypeError: list indices must be integers or slices, not str
私がすることはできません午前:
from googlefinance import getQuotes
import simplejson as json
print (json.dumps(getQuotes('FRA:BMW'), indent=2))
b=(json.dumps(getQuotes('FRA:BMW'), indent=2))
print(type(b))
a = json.loads((json.dumps(getQuotes('FRA:BMW'), indent=2)))
print(type(a))
これは私が得るものです"Index" Value(その場合:FRA)(スクリプトの最後のコード行)を出力します。
変数をかっこで囲む必要はありません。 'b = json.dumps(getQuotes( 'FRA:BMW')、indent = 2)'は動作しますが、文字列でリストにアクセスすることはできません( '[data]'の形式) 'a [" index "]'のように。あなたは 'a [0] [" Index "]' –
あなたのサポートのためにたくさんありがとう! – theamokdog