如何用类反序列化json [英] How to deserializer json with a class
本文介绍了如何用类反序列化json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jsone.count出错。
Error in jsone.count.
using Newtonsoft;
using Newtonsoft.Json;
jsonr=[{"count":[{"first":1,"second":2,"third":3},{"first":11,"second":22,"third":33},{"first":111,"second":222,"third":333}]}]
int oo = 0;
int[,] jsona = new int[100, 9];
jCount jsone = JsonConvert.DeserializeObject<jCount>(jsonr);
foreach (var element in jsone.count)
{
oo += 1;
jsona[oo, 1] = element.first;
jsona[oo, 2] = element.second;
jsona[oo, 3] = element.third;
}
public class jCount
{
private List<jplace>
}
public class jPlace
{
public int first { get; set; }
public int second { get; set; }
public int third { get; set; }
}
我尝试过:
我尝试过使用:
What I have tried:
I have tried using:
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var jsone= serializer.Deserialize<List<jcount>>(jsonr);
推荐答案
public class jCount
{
public jPlace[] count { get; set; }
}
public class jPlace
{
public int first { get; set; }
public int second { get; set; }
public int third { get; set; }
}
public ActionResult Index()
{
string jsonr = "[{\"count\":[{\"first\":1,\"second\":2,\"third\":3},{\"first\":11,\"second\":22,\"third\":33},{\"first\":111,\"second\":222,\"third\":333}]}]";
int oo = 0;
int[,] jsona = new int[100, 9];
List<jCount> jsone = JsonConvert.DeserializeObject<List<jCount>>(jsonr);
foreach (var element in jsone[0].count)
{
oo += 1;
jsona[oo, 1] = element.first;
jsona[oo, 2] = element.second;
jsona[oo, 3] = element.third;
}
这篇关于如何用类反序列化json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文