-4

How can i parse the following string to json object in C#:

string unescapedstring = " {"SettingName":"name","SettingValue":"\\log1\\log2\\","Description":"description"}" 

to get:

  {
    "SettingName": "name",
    "SettingValue": "\\log1\\log2\\",
    "Description": "description"
  }

Thanks.

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
Hicham4
  • 39
  • 1
  • 8
  • where does unescapedstring come from? – Daniel A. White Mar 24 '17 at 15:08
  • Perhaps you could explain in a sentence exactly what you want to happen. You want to format a JSON? What? This Q is unclear. – spender Mar 24 '17 at 15:08
  • For lack of clarification from OP, I don't see anything differentiating this question from the [many others on the site](https://www.google.com/search?q=c%23+parse+json+site%3Astackoverflow.com) that ask about parsing JSON. Closed. – spender Mar 24 '17 at 15:19
  • I'm passing this string : "{\"SettingName\":\"name\",\"SettingValue\":\"\\\\log1\\\\lo‌​g2\\\\\", \"Description\":\"description\"} actualy this is an object as a parameter via ajax call to a function whitch save the object in the db. – Hicham4 Mar 24 '17 at 15:21

1 Answers1

0

You can use JObject class and its method .parse which accepts string as argument:

JObject jo = JObject.Parse(unescapedstring);

Newtonsoft_Json Library

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • the string unescapedstring has a value as "{\"SettingName\":\"name\",\"SettingValue\":\"\\\\log1\\\\log2\\\\\", \"Description\":\"description\"} – Hicham4 Mar 24 '17 at 15:17