I trying to build a JavaScript function which will grab a JSON encoded array and return a value based on the requested key. I use the jQuery $.parseJSON() method to take the JSON string and convert it into a JavaScript object. Here a watered down example:
function getValue(dynamicArrayKey) {
var theArray = $.parseJSON(/* Get some JSON from a source using jQuery */);
alert('Here is the value: ' + theArray.dynamicArrayKey);
}
So the key I want will be given to the function, and it should return the resulting value. I am thinking that the JavaScript eval()
method should be used in there somewhere, but I'm not sure. Any help would be greatly appreciated.