vendredi 17 avril 2015

Accessing json using a string

I have some json : data.


I have a string build that looks like this: sections.1.subsections.0.items.0.citation.paragraph


What I need to do is manipulate that string to be able to access that value in data. So turn it into something usable: data['sections'][1]['subsections'][0]['items'][0]['citation']['paragraph']


And then use it to change that value in data. So: data['sections'][1]['subsections'][0]['items'][0]['citation']['paragraph'] = 'new value'


I can split the original string on the . and I think that gets me somewhere but I'm not at all sure how to then re-use the parts to allow me access to that value in data.


Thanks!


Aucun commentaire:

Enregistrer un commentaire