I am using the html2json which gives me back an object with child objects. Like the code below. I want to get the value of the key text. But it differs per case how many child objects there are and thus where the key text is situated.
The code I have tried but for this reason, did not work every time was this one:
json.child[0].child[0].child[0].child[0].text
And this is an example of an object:
node: 'root', child: [
{
node: 'element',
tag: 'div',
attr: { id: '1', class: 'foo' },
child: [
{
node: 'element',
tag: 'h2',
child: [
{ node: 'text', text: 'sample text with ' },
{ node: 'element', tag: 'code', child: [{ node: 'text', text: 'inline tag' }] }
]
}
]
} ]
Is there another way to access this element? I was thinking of searching for a key in the object because the key "text" only occurs once. But do not know how this would work.
All help is really appreciated!