[英]How to convert a string value to Json
I receive a string in the format given below (with double quotes around it): 我收到下面给出的格式的字符串(在其周围加上双引号):
"'{ "param" : "value"}'"
How can I convert this string into json object so that I could use it as 我如何将这个字符串转换成json对象,以便可以将其用作
alert(obj.param)
Thank you 谢谢
As I mentioned in above the string has double quotes around it. 正如我在上面提到的那样,字符串周围有双引号。 Here is an example of how I get this string
这是如何获取此字符串的示例
CSHTML CSHTML
@{
var prop = "{ \"param\" : \"value\"}";
<a data-type="@prop"></a>
}
and in JS I have this 在JS中我有这个
var obj = anchor.data('type');
I want to be able to use obj.param, how do I achieve this? 我希望能够使用obj.param,如何实现呢?
Thanks 谢谢
使用JSON.parse它将字符串解析为JSON
var obj = JSON.parse(json);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.