Newtonsoft.Json的反序列化输出
2015-06-16 09:42:14 访问(3769) 赞(0) 踩(0)
相关下载:Newtonsoft.JsonV4.5.5.14908.zip
try
{
string theResult = richTextBox1.Text;
object obj = Newtonsoft.Json.JsonConvert.DeserializeObject
(
theResult
);
if (obj is Newtonsoft.Json.Linq.JArray)
{
List<JsonSelectItem> theList = new List<JsonSelectItem>();
Newtonsoft.Json.Linq.JArray oa = obj as Newtonsoft.Json.Linq.JArray;
JsonSelectItem item = null;
foreach (object o in oa)
{
item = Newtonsoft.Json.JsonConvert.DeserializeObject
(
o.ToString(),
typeof(JsonSelectItem)
) as JsonSelectItem;
theList.Add(item);
}
StringBuilder sb = new StringBuilder();
foreach (JsonSelectItem it in theList)
{
sb.AppendLine(it.id + "|" + it.text);
}
MessageBox.Show(sb.ToString());
}
else
{
string str = obj.ToString();
MessageBox.Show(str);
}
}
catch (Exception err)
{
MsgForm.MsgShowDialog(err.Message);
}
标签:
Newtonsoft.Json的反序列化输出 


上一条:
下一条:
相关评论
发表评论