python json文件_python解析json文件

JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。在机器学习和深度学习中,解析标签文件时常常用到json文件。利用python进行标签解析是非常常见的,此处进行简单记录。json文件如下所示:

{

"version": "3.16.7",

"flags": {},

"shapes": [

{

"label": "scab",

"line_color": null,

"fill_color": null,

"points": [

[

24.307692307692307,

282.8131868131868

],

[

515.5164835164835,

787.2087912087911

]

],

"shape_type": "rectangle",

"flags": {}

},

{

"label": "scab",

"line_color": null,

"fill_color": null,

"points": [

[

529.8021978021978,

134.46153846153845

],

[

960.5714285714284,

858.6373626373626

]

],

"shape_type": "rectangle",

"flags": {}

},

{

"label": "scab",

"line_color": null,

"fill_color": null,

"points": [

[

964.967032967033,

304.79120879120876

],

[

1367.164835164835,

704.7912087912088

]

],

"shape_type": "rectangle",

"flags": {}

}

],

"lineColor": [

0,

255,

0,

128

],

"fillColor": [

255,

0,

0,

128

],

"imagePath": "TriggerQS-15208921-152.jpg",

"imageData": XXXXXXX(数据)

利用python对其进行解析时可使用json依赖包:

import json

with open(file_json, 'r', encoding='utf-8') as f:

ret_dic = json.load(f)

print(ret_dic['shapes'][0]['label'])

print(ret_dic['shapes'][0]['points'])

scab

[[159.47252747252747, 327.86813186813185], [459.4725274725274, 702.5934065934066]]

获取数据只需要关键字就可以了,结果返回的式list或者dict。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值