json字符串格式如:
[{"Title":"第零章","Content":"这是内容信息"},{"Title":" 第一章","Content":"<strong>多云,微风</strong>"},{"Title":" 第二章","Content":"降落伞"},{"Title":" 第三章","Content":"<em><u><span style="color:#006600;">力量</span></u></em>"}]
asp.net代码:
protected List<T> ArrayToList<T>(string listStr) { List<T> list = new List<T>(); if (!string.IsNullOrEmpty(listStr)) { JArray jsonRsps = JArray.Parse("[" + listStr + "]"); for (int i = 0; i < jsonRsps.Count; i++) { JsonSerializer js = new JsonSerializer(); T obj = js.Deserialize<T>(jsonRsps[i].CreateReader()); list.Add(obj); } } return list; }
引用到了命名空间:
using Newtonsoft.Json.Linq; using Newtonsoft.Json;
要转化成的数据实体类:
public class TestEntity { public string Title { get; set; } public string Content { get; set; } }