javascript - JSON Array rearrange/or filter by value of subvalue -
i'm bit stuck problem getting information out of json array. know how retrieve information , parse them. isn't issue. information facebook use jquery, did it's job fine fare.
basically, need restructure json output of following link: https://graph.facebook.com/284521968232566/photos
under tags, you'll see several items. need rearrange whole thing sorted tag. means:
pauke { [name, source, link], [name, source, link] } trompete { [name, source, link], [name, source, link] }
obviously, can see, top-level item has 1 item, there more pictures it'll grow.
this might not right form of array, i'm open approaches.
thank you
ok, iterate on data
, , on data[i].tags.data
, building result array, somthing like:
var json = {} ; // json data - needs pre-populated var result = [] ; // result array var tag ; // temporary variable each tag in turn. for(var i=0;i<json.data.length;i++) { if( typeof json.data[i].tags != 'undefined' && typeof json.data[i].tags.data != 'undefined' ) { for(var j=0;j<json.data[i].tags.data.length;j++) { tag = json.data[i].tags.data[j] ; if(typeof(tag.name != 'undefined') { if(typeof result[tag.name] == 'undefined') result[tag.name] = [] ; result[tag.name][result[tag.name].length] = { 'name' : tag.name, 'source' : json.data[i].source, 'link' : json.data[i].link } ; } } } }
this produces array (of tags), each of array (of images), 1 object containing information each image tag name.
Comments
Post a Comment