Reputation: 177
I have this string:
{'iconPath': '/img/theme/bungienet/icons/psnLogo.png', 'crossSaveOverride': 0, 'isPublic': False, 'membershipType': 3, 'membershipId': '4611686018467284386', 'displayName': 'Datto'}
from which i need to extract the data behind 'membershipId'
, i can't just cut it from character ... to character ..., because the length can be different. this is originally from the Destiny2 API and is part of this API Response:
{
"ErrorCode": 1,
"ErrorStatus": "Success",
"Message": "Ok",
"MessageData": {},
"Response": [
{
"crossSaveOverride": 0,
"displayName": "Datto",
"iconPath": "/img/theme/bungienet/icons/psnLogo.png",
"isPublic": false,
"membershipId": "4611686018467284386",
"membershipType": 3
}
],
"ThrottleSeconds": 0
}
The problem is just, that the "Response":
tag, starts a list, where everything is just Index 0 alltogether.
Upvotes: 1
Views: 62
Reputation: 9504
Try:
data = {
"ErrorCode": 1,
"ErrorStatus": "Success",
"Message": "Ok",
"MessageData": {},
"Response": [
{
"crossSaveOverride": 0,
"displayName": "Datto",
"iconPath": "/img/theme/bungienet/icons/psnLogo.png",
"isPublic": false,
"membershipId": "4611686018467284386",
"membershipType": 3
}
],
"ThrottleSeconds": 0
}
membership_id = data["Response"][0]["membershipId"]
Upvotes: 2