如何使用 Python 删除 JSON 的 headers/meta 数据

how to remove headers/meta data of JSON using Python

我正在学习 Python-JSON。我一直在尝试从 Quandl API 中提取数据,我成功加载了数据,但是当我尝试将其转换为 Python Dict 时,它抛出了一个 ValueError !

    ValueError                                Traceback (most recent call last)

 <ipython-input-10-0b58998505ee> in <module>()
----> 1 data=dict(data)

ValueError: dictionary update sequence element #0 has length 1; 2 is required

下面是我的代码,

import json,urllib2
url = "https://www.quandl.com/api/v3/datasets/NASDAQOMX/NQASIA0001LMGBPT.json"
loaded = urllib2.urlopen(url).read()
data = json.loads(loaded)
type(data) # shows string
data=dict(data) # here i'm getting value error

这就是数据的样子

  {"dataset":{"id":12835494,"dataset_code":"NQASIA0001LMGBPT","database_code":"NASDAQOMX","name":"NASDAQ Asia Oil \u0026 Gas Large Mid Cap GBP TR Index (NQASIA0001LMGBPT)","description":"  \u003cp\u003eThe comprehensive NASDAQ Global Index Family covers international securities segmented by geography, sector, and size. NASDAQ OMX's transparent and rules-based selection method results in a complete representation of the global investable equity marketplace. The indexes cover 45 individual countries within Developed and Emerging Markets, and facilitate a multitude of tracking, trading, and investing opportunities.\u003c/p\u003e\n  \u003cp\u003e\u003cb\u003eComponents:\u003c/b\u003e \u003ca href=https://indexes.nasdaqomx.com/Index/Weighting/NQASIA0001LMGBPT\u003e40\u003c/a\u003e\u003c/p\u003e\n  \u003cp\u003e\u003cb\u003eCurrency:\u003c/b\u003e GBP\n  \u003cp\u003e\u003cb\u003eEntitlements:\u003c/b\u003e \u003ca href=https://indexes.nasdaqomx.com/Index/Overview/NQASIA0001LMGBP\u003eNASDAQ Global Index Family\u003c/a\u003e\u003c/p\u003e\n  \u003cp\u003e\u003cb\u003eTotal Market Value:\u003c/b\u003e is the sum of the market value of all companies in the index.\u003c/p\u003e\n  \u003cp\u003e\u003cb\u003eDividend Market Value:\u003c/b\u003e is the sum of the market value of all dividends generated by companies in the index. \u003c/p\u003e\n  \u003cp\u003e\u003cb\u003eTerms of Use:\u003c/b\u003e This data cannot be republished or used as the basis of a financial product without the permission of Nasdaq OMX.\u003c/p\u003e\n\n","refreshed_at":"2016-03-05T02:26:29.308Z","newest_available_date":"2016-03-04","oldest_available_date":"2001-03-30","column_names":["Trade Date","Index Value","High","Low","Total Market Value","Dividend Market Value"],"frequency":"daily","type":"Time Series","premium":false,"limit":null,"transform":null,"column_index":null,"start_date":"2001-03-30","end_date":"2016-03-04","data":[["2016-03-04",901.68,901.68,901.68,120990409547.0,10184040.0],["2016-03-03",888.22,888.22,888.22,119195278884.0,74919059.0],["2016-03-02",876.66,876.66,876.66,117717482960.0,0.0],["2016-03-01",861.69,861.69,861.69,115706487736.0,31420802.0],["2016-02-29",840.1,840.1,840.1,112838933060.0,0.0],["2016-02-26",856.96,856.96,856.96,115103827172.0,0.0],["2016-02-25",836.8,836.8,836.8,112395722181.0,43584397.0],["2016-02-24",846.48,846.48,846.48,113739936161.0,29138803.0],["2016-02-23",846.58,846.58,846.58,113782545450.0,0.0],["2016-02-22",839.75,839.75,839.75,112864607315.0,0.0],["2016-02-19",833.0,833.0,833.0,111957089747.0,0.0],["2016-02-18",832.63,832.63,832.63,111907945844.0,0.0],["2016-02-17",808.34,808.34,808.34,108642319107.0,0.0],["2016-02-16",821.18,821.18,821.18,110368331892.0,7742456.0],["2016-02-15",801.89,801.89,801.89,107783839163.0,0.0],["2016-02-12",770.54,770.54,770.54,103569144401.0,0.0],["2016-02-

我想我在这里遗漏了一些东西,我是否必须对 URL 做任何事情,传递参数?还是我必须在 data=dict(data) 之前包括任何步骤?

我在发布这个问题之前检查了 Whosebug,我没有成功,我做了 google,我点击的每个站点都使用 Quandl 包,(下面的link)# Quandl(数据集)

任何 description/tutorial 都会让我更好地理解这一点。感谢您的宝贵时间。

PS:我想在不使用 pandas 和任何其他库的情况下执行此操作。

谢谢,

Retrieving data from Quandl with Python

使用requests:

import json, requests
url = "https://www.quandl.com/api/v3/datasets/NASDAQOMX/NQASIA0001LMGBPT.json"
data = requests.get(url).json()
print(data)