我正在编写一个使用 python 请求从 URL 读取 json 的类对象。json 字符串很奇怪,因为浮点数、日期和整数都是字符串。
{
"financialStatementList" : [ {
"symbol" : "HUBS",
"financials" : [ {
"date" : "2018-12-31",
"Revenue" : "512980000.0",
"Revenue Growth" : "0.3657",
"Cost of Revenue" : "100357000.0",
"Gross Profit" : "412623000.0",
"R&D Expenses" : "117603000.0",
"SG&A Expense" : "343278000.0",
"Operating Expenses" : "460881000.0",
"Operating Income" : "-48258000.0",
"Interest Expense" : "21386000.0",
"Earnings before Tax" : "-61960000.0",
"Income Tax Expense" : "1868000.0",
"Net Income - Non-Controlling int" : "0.0",
"Net Income - Discontinued ops" : "0.0",
"Net Income" : "-63828000.0",
"Preferred Dividends" : "0.0",
"Net Income Com" : "-63828000.0",
"EPS" : "-1.66",
"EPS Diluted" : "-1.66",
"Weighted Average Shs Out" : "39232269.0",
"Weighted Average Shs Out (Dil)" : "38529000.0",
"Dividend per Share" : "0.0",
"Gross Margin" : "0.8044",
"EBITDA Margin" : "-0.033",
"EBIT Margin" : "-0.0791",
"Profit Margin" : "-0.124",
"Free Cash Flow margin" : "0.1002",
"EBITDA" : "-17146000.0",
"EBIT" : "-40574000.0",
"Consolidated Income" : "-63828000.0",
"Earnings Before Tax Margin" : "-0.1208",
"Net Profit Margin" : "-0.1244"
}
api端点的json示例如下: financialmodelingprep.com
我的问题是,当我对此进行解码时,我最终得到的是对象/字符串,而不是浮点数或整数。
我试过了:
r = requests.get(url, params)
jd = json.loads(r.text)
也:
r = requests.get(url, params)
jd - r.json()
并且,还有使用 kwargs 的变体,例如 parse_float = float 或 parse_float=Decimal
我的最终目标是使用浮点数、整数和日期将其转换为格式。
眼眸繁星
相关分类