Reputation: 179
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
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
@{
var prop = "{ \"param\" : \"value\"}";
<a data-type="@prop"></a>
}
and in JS I have this
var obj = anchor.data('type');
I want to be able to use obj.param, how do I achieve this?
Thanks
Upvotes: 0
Views: 64
Reputation: 983
Use JSON.parse it parses a string as a JSON
var obj = JSON.parse(json);
Upvotes: 4