Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign a JSON value to a string variable

Tags:

json

string

c#

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 C# 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.

like image 217
Bohn Avatar asked Oct 18 '25 08:10

Bohn


1 Answers

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";
like image 184
knechtrootrecht Avatar answered Oct 19 '25 22:10

knechtrootrecht



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!