简体   繁体   中英

get the key value from javascript object with jQuery

i have this object:

"{"logEntries":[],"value":"-8","text":"Europe","enabled":true}"

how do i get the value of the "value" key in jQuery with minimum code?. in this case "-8".

I suggest :

var myObject = '{"logEntries":[], "value":"-8", "text":"Europe", "enabled":true}';
alert($.parseJSON(myObject).value);
var obj = '{"logEntries":[],"value":"-8","text":"Europe","enabled":true}';
obj = $.parseJSON(obj);
console.log(obj.value);

You had double quotes inside double quotes, you can't do that, you need to wrap it in single quotes.

Also, you don't need the quotes here in the first place, just make an object, not a string, so you don't to parse.

var obj = {"logEntries":[],"value":"-8","text":"Europe","enabled":true};
console.log(obj.value);
var x = {"logEntries":[],"value":"-8","text":"Europe","enabled":true}

var valueProperty = x.value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM