Bohn Bohn - 1 year ago 138
JSON Question

How to assign a JSON value to a string variable

Some value is saved in JSON format in DB and if I copy it from DB it looks like this:

[{"id":"FAC2SOUTHX","name":"South District MW ","description":"South District MW ","selected":true,"required":false,"sortOrder":10}]

Now I want to write a unit test that for its mock object I need to pass that value and the mock value is a string. But
giving error if I want to assign that value to a string variable. So I thought all I have to do is to prefix it with a
but didn't work either.
So how can I assign that value to a string variable.

ivo ivo
Answer Source

You have to comment all qoutes with a backslash so the string is recognized as a String e.g.

string s = "My string with \" qouted \" Values";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download