[英]deserialize json in datatable from javascriptserializer
Hi I have to parse json
data into datatable
object. 嗨,我必须将json
数据解析为datatable
对象。 Bellow is my json
data 贝娄是我的json
数据
{
"Figurative Expressions (Idioms)" : {
"A" : [
{
"One word" : "Above all",
"Phrase" : "chiefly, before everything else"
},
{
"One word" : "Above-board",
"Phrase" : "not open to question, honest, straight-forward, beyond reproach"
},
{
"One word" : "Above-par",
"Phrase" : "of superior quality"
},
{
"One word" : "On account of ",
"Phrase" : "for the sake of"
},
{
"One word" : "On no account",
"Phrase" : "not for any reason"
},
{
"One word" : "To give a good account of oneself",
"Phrase" : "to act with credit to oneself"
}
]
}
}
How do we parse this json
data in datatable
? 我们如何解析这个json
数据datatable
?
As I tried with javascriptserializer
, it was parsed successfully but didn't get anything in datatable
. 正如我试过javascriptserializer
,它被成功解析,但没有得到任何东西datatable
。
JavaScriptSerializer js = new JavaScriptSerializer();
DataTable data1 = js.Deserialize<DataTable>(text);
It could be due to the fact that the Json in your example is not a pure array - but rather an object with one attribute called A which is the actual array. 可能是由于您的示例中的Json不是纯数组-而是一个对象带有一个称为A的属性,它是实际数组。
My suggestion is to try to deserialize only text that defines A attribute (starting with square bracket) - so pure Json array. 我的建议是尝试反序列化仅定义A属性的文本(以方括号开头)-纯Json数组。 This should deserialise into a Datatable fine. 这应该反序列化为Datatable的罚款。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.