I've a large JSON string describing some data. I'd like to loop through this and replace value of all properties named "Key". How can I achieve this using jQuery or plain Javascript?
+1
A:
for ( var i in data ) {
for ( var k in data[i] ) {
if ( k == 'Key' ) {
data[i][k] = 'new value';
}
}
}
hsz
2010-08-09 13:30:26
+1
A:
var item = $.parseJson("jsonstring...");
var target = "Key";
for (var k in item) {
if (item.hasOwnProperty(k) && item[k].hasOwnProperty(target)) {
item[k][target] = "replacement value"
}
}
Or similar, depending on the structure of your JSON. This is assuming it's a list of objects.
jeremiahd
2010-08-09 13:31:07
A:
for (property in setJson)
{ if (property != 'Key') //do some think }
Haroldis
2010-08-09 13:31:14