python3生成json

深碍√TFBOYSˉ_ 2022-11-09 14:16 250阅读 0赞
  1. import json
  2. from collections import defaultdict
  3. 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']
  4. body = defaultdict(list)
  5. dicts = defaultdict(list)
  6. for i in range(len(res)):
  7. pos_dict = {
  8. "id": i,
  9. "boundingBox": res[i]
  10. }
  11. body['element'].append(pos_dict)
  12. dicts = {"imagename": 'image_path', "body": body}
  13. json_str = json.dumps(dicts, indent=4).encode('utf-8').decode("unicode-escape")
  14. print(json_str)

发表评论

表情:
评论列表 (有 0 条评论,250人围观)

还没有评论,来说两句吧...

相关阅读