如何使用newtonsoft将字符串转换为列表对象 [英] How do I convert a string to a list object with newtonsoft
本文介绍了如何使用newtonsoft将字符串转换为列表对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Newtonsoft将字符串转换为List对象。
data2有要列出错误的字符串。
How do I convert a string to a List object with Newtonsoft.
data2 has the string to list error.
string json2 = "[{\"id\":\"1\",\"datetime\":\"04/10/2017\",\"col1\":\"1\",\"col2\":\"2\",\"col3\":\"3\"}]";
List<data> data2 = JsonConvert.DeserializeObject<List<data>>(json2);
public class data
{
public int id { get; set; }
public string datetime { get; set; }
public int col1 { get; set; }
public int col2 { get; set; }
public int col3 { get; set; }
}
我的尝试:
我尝试过不同的序列化字符串类型。
What I have tried:
I have tried different serialization string types.
推荐答案
你的代码应该是:
Your code should be:
data mydata = JsonConvert.DeserializeObject<data>(json2);
这篇关于如何使用newtonsoft将字符串转换为列表对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文