python从json格式的列表中获取参数值,如何使用python从列表Json中获取数据?

I am new to python and have tried to get data from a python json document , what I try to do is pass the information to python and json from python print a pdf with a table style.

My code in json is

[

{

"files": 0,

"data": [

{"name": "RFC", "value": "XXXXXXX", "attId": 01},

{"name": "NOMBRE", "value": "JOSE", "attId": 02},

{"name": "APELLIDO PATERNO", "value": "MONTIEL", "attId": 03},

{"name": "APELLIDO MATERNO", "value": "MENDOZA", "attId": 04},

{"name": "FECHA NACIMIENTO", "value": "1989-02-04", "attId": 05}

],

"dirId": 1,

"docId": 4,

"structure": {

"name": "personales",

"folioId": 22

}

},

{

"files": 0,

"data": [

{"name": "CALLE", "value": "AMOR", "attId": 06},

{"name": "No. EXTERIOR", "value": "4", "attId": 07},

{"name": "No. INTERIOR", "value": "2", "attId": 08},

{"name": "C.P.", "value": "55060", "attId": 09},

{"name": "ENTIDAD", "value": "ESTADO DE MEXICO", "attId": 10},

{"name": "MUNICIPIO", "value": "ECATEPEC", "attId": 11},

{"name": "COLONIA", "value": "INDUSTRIAL", "attId": 12}

],

"dirId": 1,

"docId": 4,

"structure": {

"name": "direccion",

"folioId": 22

}

}

]

and in python i tip the next code

import json

f= open(prueba.json)

prueba = json.load(f)

prueba

print correctly content of json,but my idea is get only for example:

Nombre,Jose

and then use the parameters to build the table in pdf

I have tried the following

import json

json_data = []

with open('prueba.json') as json_file:

json_data = json.load(json_file)

for key, value in json_data.iteritems():

print key;

for item in value:

print item

for key, value in json_data.iteritems():

print key;

for item in value:

print item

But i have the next error:

AttributeError : 'list' object has no attribute 'iteritems'

I 'm trying to do something for them but I must get each data of json

解决方案json_data = [] # your list with json objects (dicts)

for item in json_data:

for data_item in item['data']:

print data_item['name'], data_item['value']

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值