大佬教程收集整理的这篇文章主要介绍了如何获得正确的json打印,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在向我的 Json
API 获取一些 flask
数据。
if len(IDxs) > 0:
# loop over the indexes we are keePing
for i in IDxs.flatten():
data = []
info = {}
info['label'] = LABELS[classIDs[i]]
info['accuracy'] = confIDences[i]
info['rectangle'] = {"height":Boxes[i][0],"left": Boxes[i][1],"top": Boxes[i][2],"wIDth": Boxes[i][3]}
data.append(deepcopy(info))
res = Json.dumps(data,indent=2)
我在服务器中再添加 1 个字段。字段 ID
。
for l in range(1,128):
img = cv2.imread("image{}".format(l),cv2.IMREAD_ANYcolor);
# load the neural net. Should be local to this method as its multi-threaded endpoint
nets = load_model(CFG,Weights)
s = do_preDiction(img,nets,Lables)
result = {}
result['ID'] = uID
result['object'] = s
return result
我得到的输出
Thread : ThreadPoolExecutor-0_1,input image: inputfolder\000000563577.jpg,output:{
"ID": "a42feb50-7df8-5fac-aa8f-0342f0d11727","object": "[\n {\n \"label\": \"person\",\n \"accuracy\": 0.9530006051063538,\n \"rectangle\": {\n \"height\": 297,\n \"left\": 224,\n \"t
op\": 139,\n \"wIDth\": 259\n }\n }\n]"
}
所需的输出:-
{
"ID": "2b7082f5-d31a-54b7-a46e-5e4889bf69bd","objects": [
{
"label": "person","accuracy": 0.8790481352806091,"rectangle": {"height": 114,"left": 380,"top": 363,"wIDth": 254}
},{
"label": "person","accuracy": 0.8877481352806091,"left": 180,"top": 63,"wIDth": 254}
}
]
新行似乎在正确的位置,但我无法正确打印。
你得到了一个 json 字符串,为了将它转换回一个 json,你必须在它上面调用 json.loads()。 P.S :你没有问过它,但在你的第二段代码中,你在每次迭代中加载模型,这根本没有效率,只在循环外加载一次。
以上是大佬教程为你收集整理的如何获得正确的json打印全部内容,希望文章能够帮你解决如何获得正确的json打印所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。