1

I have this string but I need to extract specific values from the string/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":{}}}

I have this code in Python 3.7 to extract this string from URL, then I need to get some values, for example from "Cod" is "XXX96000051"

Code:

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")
0

1 Answer 1

-1

You should access values of a dict via keys, so to get the value of the key Cod, which is nested under the key Artigo, you should use:

result['Artigo']['Cod']
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.