python3生成json

import json
from collections import defaultdict
res=['253,219,272,219,272,237,253,237', '385,196,399,195,401,212,387,213', '138,186,160,188,157,218,135,216', '220,165,252,165,252,197,220,197', '314,160,333,160,333,188,314,188', '273,159,294,159,294,192,273,192', '191,148,205,148,205,164,191,164', '391,144,417,144,417,176,391,176', '283,150,288,150,288,153,283,153', '335,133,356,133,356,165,335,165', '381,114,397,114,397,131,381,131', '449,108,471,110,469,139,447,137', '214,111,227,111,227,128,214,128', '262,100,278,100,278,125,262,125', '323,97,345,97,345,116,323,116', '366,89,384,89,384,105,366,105', '108,84,128,84,128,113,108,113', '192,73,224,72,226,104,193,105', '242,74,263,75,262,103,241,102', '430,57,448,58,446,86,428,85', '288,50,309,52,307,79,286,78', '345,52,363,52,363,81,345,81', '181,40,199,40,199,56,181,56', '343,19,355,19,355,34,343,34']

body = defaultdict(list)
dicts = defaultdict(list)
for i in range(len(res)):
        pos_dict = {
            "id": i,
            "boundingBox": res[i]
        }
        body['element'].append(pos_dict)
dicts = {"imagename": 'image_path', "body": body}
json_str = json.dumps(dicts, indent=4).encode('utf-8').decode("unicode-escape")
print(json_str)

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值