使用JSON d的python api调用

2024-09-29 19:35:59 发布

您现在位置:Python中文网/ 问答频道 /正文

对于pythonapi调用,我有下面的JSON数据示例

我可以通过调用(swell.*)(swell.minBreakingHeight)来获取数据,它会毫无顾虑地返回所有的膨胀数据。所以工作请求可以吗

我似乎不能用成功的例子来缩小范围 显然上面的格式是不正确的,并且一直返回[]

我怎么才能进入那个额外级别?在

[{
timestamp: 1366902000,
localTimestamp: 1366902000,
issueTimestamp: 1366848000,
fadedRating: 0,
solidRating: 0,
swell: {
    minBreakingHeight: 1,
    absMinBreakingHeight: 1.06,
    maxBreakingHeight: 2,
    absMaxBreakingHeight: 1.66,
    unit: "ft",
    components: {
         combined: {
         height: 1.1,
         period: 14,
         direction: 93.25,
         compassDirection: "W"
    },
    primary: {
         height: 1,
         period: 7,
         direction: 83.37,
         compassDirection: "W"
    },

Tags: 数据json示例pythonapi格式级别timestamp例子
1条回答
网友
1楼 · 发布于 2024-09-29 19:35:59

使用数据段:

data = [{
'timestamp': 1366902000,
'localTimestamp': 1366902000,
'issueTimestamp': 1366848000,
'fadedRating': 0,
'solidRating': 0,
'swell': {
    'minBreakingHeight': 1,
    'absMinBreakingHeight': 1.06,
    'maxBreakingHeight': 2,
    'absMaxBreakingHeight': 1.66,
    'unit': "ft",
    'components': {
         'combined': {
         'height': 1.1,
         'period': 14,
         'direction': 93.25,
         'compassDirection': "W"
    },
    'primary': {
         'height': 1,
         'period': 7,
         'direction': 83.37,
         'compassDirection': "W"
    }
}
}
}
]

In [54]: data[0]['timestamp']
Out[54]: 1366902000

In [55]: data[0]['swell']['components']['primary']['height']
Out[55]: 1

所以使用你的点符号,你应该打电话给:

^{pr2}$

有关解析json文件的更多信息,请参阅另一个stackoverflow question

相关问题 更多 >

    热门问题