I have a question because it is difficult to extract the desired value when I receive the json format data. : : )
Example:
[
{
"date": "2020-12-26",
"year": 2020,
"quarter": 1,
"class": {
"name": [
{
"code": "Youngsoo",
"values": 15
},
{
"Code": "Hee Min",
"values": 16
}
]
}
}
]
If the code
value is "Youngsoo"
, we would like to extract and
values
from the data.
I'm asking you how you can do it.
You can just look at each other, but I'm not sure what you're curious about.
t = """
[
{
"date": "2020-12-26",
"year": 2020,
"quarter": 1,
"class": {
"name": [
{
"code": "Youngsoo",
"values": 15
},
{
"Code": "Hee Min",
"values": 16
}
]
}
}
]
"""
import json
d = json.loads(t)
print(d)
print(d[0])
print(d[0]["class"]["name"])
print ([cv for cvind[0]["class"]["name"] if cv["code"] == "accept"])
t = """
[
{
"date": "2020-12-26",
"year": 2020,
"quarter": 1,
"class": {
"name": [
{
"code": "Youngsoo",
"values": 15
},
{
"Code": "Hee Min",
"values": 16
}
]
}
},
{
"date": "2020-12-26",
"year": 2020,
"quarter": 1,
"class": {
"name": [
{
"code": "Youngsoo",
"values": 15
},
{
"Code": "Hee Min",
"values": 16
}
]
}
}
]
"""
import json
d = json.loads(t)
print(d)
print([e for e in d])
print([ e["class"]["name"] for e in d])
print ([cv for end for cv in e["class"]["name"] if cv["code"] == "accept"])
© 2024 OneMinuteCode. All rights reserved.