简体   繁体   English

按字符串名称访问parseJSON

[英]Access parseJSON by string name

I'm jsoning ac# const class, getting name-value-pairs. 我正在jsoning ac #const class,获得名称 - 值对。 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? 这显然不起作用 - 有没有办法从我的json-input使用字符串名称获取我的值?

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. 了解更多如何在MDN上操作对象。

您可以使用:

JSON.parse(constantClass)['proptery']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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