Just diving into Angular and I'm loving it.
Struggling with parsing a JSON feed that has namespaces, need some help:
Here's an example from the JSON feed:
"title": {
"label": "Fuse"
},
"im:name": {
"label": "John Doe"
},
"im:image": [ {
"label": "70x70",
"attributes": {
"height": "55"
}
}, {
"label": "80x80",
"attributes": {
"height": "60",
"im:link": "www.google.com"
}
}, {
"label": "90x90",
"attributes": {
"height": "170",
"im:link": "www.yahoo.com"
}
}],
I can parse items without namespaces like this:
<p ng-repeat="item in results.feed['entry']">
title: {{item.title['label']}}
</p>
But struggling to display items with namespaces using these methods:
name: {{item.['im:name']['label']}}
OR
name: {{item.['im-name']['label']}}
OR
name: {{item.['im->name']['label']}}
As a newbie, I tried using namespaces in HTML code:
<div xmlns:im="http://www.aol.com" id="im-app" im-app="im">
<p ng-repeat="item in results.feed['entry']">
…namespace code in here…
</p>
</div>
But no luck there.
Bonus question: What if a namespace contains attributes with more namespaces?
Any assistance would be greatly appreciated.
Thank you! Roc.
Craig already answered the initial question, but here's a reference for others:
If you want to target a specific key inside an object set like in "im:image":[], use this syntax:
"im:image":[
{
"label":"google",
"attributes":{
"height":"55"
}
},
{
"label":"yahoo",
"attributes":{
"height":"60"
}
},
{
"label":"aol",
"attributes":{
"height":"170"
}
}
{{item['im:image'][2]['label']}}
This will retrieve the label of the third key in that set.
Thanks.