0

我有这种json数据:

{
  "data": [
    {
      "alpha": 1.93358, 
      "beta": 1.98596, 
      "confidence": 0.051
    }, 
    {
      "alpha": 1.92124, 
      "beta": 3.91954, 
      "confidence": 0.207
    },
    ...

我只想要beta价值观。

我所做的是使用列表理解:

[x['beta'] for x in data]

但由于某种原因,我觉得有更合适的方法来解析这个字典并获得相同的数据,我没有看到它。

有没有更好的办法?

4

1 回答 1

0

Looks perfect to me. I'm sure you're already using the json loader to interpret this into a python dictionary, but just in-case you're not familiar example is below:

import json

def get_data(json_data) :
    data = json.loads(json_data)['data']
    return [x['beta'] for x in data]
于 2013-01-16T23:25:46.917 回答