I have a JSON file that has more name value pairs than I care to type in. Either lazy or elegant. Instead of using what I have below where I have to type in all the name values pairs there must be a property of val like val.name so not to have to type all the other pairs out. What’s the proper terminology to search find the answer? or the code would be nice too 🙂
This is what I started using when I thought, “crap, I have to type all that *#&@$ out!”
$.each(data, function(key, val) {
items.push(key + val.TimeStamp + val.bandwidth + );
JSON
{
"Router": "HS-DSCS1",
"router_data": [
{
"TimeStamp": "2012/01/01 06:00:00",
"NeighborIP": "192.168.1.1",
"State": "Full",
"Bytes001": "21362.95663",
"Bytes002": "2.67 KB",
"Bytes003": "9887.99707",
"Bytes004": "1.24 KB",
"Bytes005": "Serial0/1/0"
}
]
}
Seems like you’re just doing string concatenation. If so …
DEMO: http://jsfiddle.net/ZVDcy/
Or if you’re building a new Array, you could do this…
DEMO: http://jsfiddle.net/ZVDcy/1/