To retrieve the value of foo3
, you can just use JSON.Parse
with a callback function that will only return the value of foo3
if it is present.
Here is a working snippet:
var text="{"foo1":"1123","foo2":"332","foo3":"23-SEP-15"}";
JSON.parse(text, function(k,v){
if (k === 'foo3') {
document.write(v);
}
return v;
});
Here, in function(k,v)
, k
stands for the key and v
stands for the value.
You can find more working examples of how to parse JSON with JavaScript at the provided MDN link above.
1
solved how to select a specific entry from a JSON object