简体   繁体   English

C#在json属性中反序列化html

[英]C# Deserialize html inside json property

How can I decode with console application a html string inside json property like this?: 如何使用控制台应用程序解码json属性中的html字符串,如下所示?:

{
    "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! 提前致谢!

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 ) 添加对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 html变量将包含结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM