从String /“ Json”

时间:2019-03-03 23:47:28

标签: python json string list

我有这个字符串,但是我需要从字符串/ json中提取特定的值。

{"Artigo":{"NrReg":"81846","Cod":"XXX96000051","Desc_Web":"XX 296 00 BLACK","Desc_Agregadora":"XX 296","PVO":"69","NlDes":"3","Cat1_GrpArtigos":"\t2","Cat2_SegMarca":"s\t0","Cat3_SegAcessorios":{},"Cat4_Categoria":{},"Marca":{},"Attr_Sexo":{},"Attr_MatGenerico":{},"Attr_TipoOculo":{},"Profile_V":"1","Profile_S":"0","StockQty":"0","Image":"XXX96000051.jpg","ImageF":{}}}

我在Python 3.7中具有此代码以从URL提取此字符串,然后需要获取一些值,例如,从“ Cod”为“ XXX96000051”

代码:

import requests
import time
import json

url = "http://www.urlsite.test"
data = requests.get(url)
result = data.json()


print(result)
t0 = time.time()

for i in result:
    print(i[0])

print("Total time " + str(time.time() - t0) + " sec")

1 个答案:

答案 0 :(得分:-1)

您应该通过键访问字典的值,因此要获取嵌套在键Cod下的键Artigo的值,您应该使用:

result['Artigo']['Cod']