I am trying to figure out how I can get a property value from a jsonObject by giving a property name
well, let’s say I have the object
var jsonObj = eval('{"key1":"value1","key2":"value2"}');
and I want to get a value by using a method
function getPropertyValue(key){
return jsonObj.key;
}
alert(getPropertyValue("key1"));
I know that I can get the value by using jsonObj.Key but I want to do it by use a method
Is it possible?
For one: Parse your JSON using the correct methods and avoid using
eval:And your method can look like this: