0

How can I decode with console application a html string inside json property like this?:

{
    "type":"text",
    "html":"\n\n\n <div class=\"class\">\n          <ul>\n\n\n  <li class=\"class1\">\n\n\n\n\n\n<a href=\"url\" class=\"class2\"   title='title'  \n >\n    title\n</a>\n\n  ..."
}

thanks in advance!

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
Simone
  • 27
  • 2
  • 7
  • Use Json.Net for deserialization. This can be deserialized to a Dictionary – Sir Rufo Jul 04 '17 at 17:33
  • Yes I done it using Newtonsoft.Json.JsonConvert.DeserializeObject(source); but the html text it's always with \n \" etc.. :( – Simone Jul 04 '17 at 19:45
  • I cannot reproduce your issue, see [Online example](https://dotnetfiddle.net/fRpT05) - But I guess you are getting confused by the debugger view of the variable content and that is always an escaped version – Sir Rufo Jul 04 '17 at 20:07
  • Yes I am, sorry that work it **thankssss!** – Simone Jul 04 '17 at 20:17

1 Answers1

0

Create a class:

public class JsonClass
{
public string type{get;set;}
public string html{get;set;}
}

Add a reference to Newtonsoft ( http://www.newtonsoft.com/json)

Next, deserialize the content:

string json = @"{
     //your json
}";
var response = 
JsonConvert.DeserializeObject<JsonClass>(json);

var html = response.html;

The html variable will contain the results

Yasirmx
  • 417
  • 3
  • 9
  • sorry I think that I explanated bad my problem :( ; when i deserialize that with JsonConvert.DeserializeObject(json); the html text is not deserialized and contain charapter like \n \" etc.. – Simone Jul 04 '17 at 19:51
  • Hello have a look at this thread https://stackoverflow.com/questions/238002/replace-line-breaks-in-a-string-c-sharp please mark as answer if this solves your problem – Yasirmx Jul 06 '17 at 07:57