Understanding How Python 3 Series Gets Values from Json

Asked 2 years ago, Updated 2 years ago, 112 views

{'resultCount':3,
 'results':
 [
  { 
   'collectionViewUrl': 'https://itunes.apple.com/jp/album/stab-me-in-the-back/id573901505?i=573901752&uo=4'
  }
  {...}
  {...}
 ]
}

How do I get the value of the key "collectionViewURL" from the Json structure in Python 3 series?

python json python3

2022-09-30 19:45

1 Answers

As already mentioned in the comment, it seems that the JSON listed is incorrect, but I am writing on the premise that it can be parsed correctly.

Python comes standard with the json package and is available.

import json

JSON_STRING=""
{
 "resultCount"—3,
 "results": [
  {
   "collectionViewUrl": "https://itunes.apple.com/jp/album/stab-me-in-the-back/id573901505?i=573901752&uo=4"
  }
 ]
}
"""

json_obj=json.loads(JSON_STRING)
print(json_obj['results'][0]['collectionViewUrl'])


2022-09-30 19:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.