简体   繁体   中英

Access parseJSON by string name

I'm jsoning ac# const class, getting name-value-pairs. I need to access them by string-name on client side, eg

return $.parseJSON(constantClass).'property';

This is obviously not working - is there any way to get my value from my json-input using a string name?

Try to access them as array keys (very familiar to associative arrays):

return $.parseJSON(constantClass)['property'];

See more how you can operate with objects at MDN.

您可以使用:

JSON.parse(constantClass)['proptery']

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