T
Tom Cole
Let's say I have the following JSON string returned from a server-side
process:
{ values: [{"name": "value1", "value": "1"},{"name": "value2",
"value": "0"},{"name": "operand", "value": "/"},{"name": "result",
"value": "NaN"},{"name": "error", "value": "Divide by 0"}] }
I then create a JSON object from it using eval() (tell me if this is
not what should be done).
My question is this...how do I determine (without going through every
single record) if there is a name=error in the values array?
Here's what I do now, it can't be optimum:
var object = eval('{ values: [{"name": "value1", "value": "1"},
{"name": "value2", "value": "0"},{"name": "operand", "value": "/"},
{"name": "result", "value": "NaN"},{"name": "error", "value": "Divide
by 0"}] }');
for (var i = 0; i < object.values.length; i++) {
if (object.values.name == 'error') {
//do stuff...
}
}
I thought I'd try object.values.name['error'] of course that didn't
work...
Any help would be appreciated.
process:
{ values: [{"name": "value1", "value": "1"},{"name": "value2",
"value": "0"},{"name": "operand", "value": "/"},{"name": "result",
"value": "NaN"},{"name": "error", "value": "Divide by 0"}] }
I then create a JSON object from it using eval() (tell me if this is
not what should be done).
My question is this...how do I determine (without going through every
single record) if there is a name=error in the values array?
Here's what I do now, it can't be optimum:
var object = eval('{ values: [{"name": "value1", "value": "1"},
{"name": "value2", "value": "0"},{"name": "operand", "value": "/"},
{"name": "result", "value": "NaN"},{"name": "error", "value": "Divide
by 0"}] }');
for (var i = 0; i < object.values.length; i++) {
if (object.values.name == 'error') {
//do stuff...
}
}
I thought I'd try object.values.name['error'] of course that didn't
work...
Any help would be appreciated.