0

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


Edit

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

somedude
  • 159
  • 3
  • 11

1 Answers1

4

Use JSON.parse it parses a string as a JSON

var obj = JSON.parse(json);
Isaac
  • 971
  • 1
  • 7
  • 13
  • @csharp_beginner replace `var obj = anchor.data('type');` by `var obj = JSON.parse(prop);` – Isaac Sep 25 '14 at 22:42