我有这个json
{
"home": {
"0_15": {
"goals": 7,
"percentage": 14
},
"15_30": {
"goals": 6,
"percentage": 12
},
"30_45": {
"goals": 11,
"percentage": 22
},
"45_60": {
"goals": 4,
"percentage": 8
},
"60_75": {
"goals": 8,
"percentage": 16
},
"75_90": {
"goals": 14,
"percentage": 28
}
},
"away": {
"0_15": {
"goals": 7,
"percentage": 15.56
},
"15_30": {
"goals": 7,
"percentage": 15.56
},
"30_45": {
"goals": 5,
"percentage": 11.11
},
"45_60": {
"goals": 6,
"percentage": 13.33
},
"60_75": {
"goals": 13,
"percentage": 28.89
},
"75_90": {
"goals": 7,
"percentage": 15.56
}
}
}
我正在尝试使用this工具生成类。当我粘贴到这个工具上时,它会说:
解析您的JSON不起作用。请确保它有效。
所以我试着用this工具检查这个json是否有效,这个json是有效的,为什么不能生成c#类?
发布于 2018-06-25 01:24:28
如果你在运行时解析JSON
,我推荐使用NewtonSoft
nuget包。它很神奇,可能也是使用最多的。
如果你想复制和粘贴JSON
并创建一个类,我推荐使用Visual Studio来完成这项工作。
只需像复制粘贴一样复制JSON
,在Visual Studio中打开一个类(或创建一个新类),然后选择
编辑->粘贴特殊->作为类粘贴JSON
它会把它变成你需要的C#类。
上面的JSON
结果如下(您可以根据需要进行编辑和修改)。
public class Rootobject
{
public Home home { get; set; }
public Away away { get; set; }
}
public class Home
{
public _0_15 _0_15 { get; set; }
public _15_30 _15_30 { get; set; }
public _30_45 _30_45 { get; set; }
public _45_60 _45_60 { get; set; }
public _60_75 _60_75 { get; set; }
public _75_90 _75_90 { get; set; }
}
public class _0_15
{
public int goals { get; set; }
public int percentage { get; set; }
}
public class _15_30
{
public int goals { get; set; }
public int percentage { get; set; }
}
public class _30_45
{
public int goals { get; set; }
public int percentage { get; set; }
}
public class _45_60
{
public int goals { get; set; }
public int percentage { get; set; }
}
public class _60_75
{
public int goals { get; set; }
public int percentage { get; set; }
}
public class _75_90
{
public int goals { get; set; }
public int percentage { get; set; }
}
public class Away
{
public _0_151 _0_15 { get; set; }
public _15_301 _15_30 { get; set; }
public _30_451 _30_45 { get; set; }
public _45_601 _45_60 { get; set; }
public _60_751 _60_75 { get; set; }
public _75_901 _75_90 { get; set; }
}
public class _0_151
{
public int goals { get; set; }
public float percentage { get; set; }
}
public class _15_301
{
public int goals { get; set; }
public float percentage { get; set; }
}
public class _30_451
{
public int goals { get; set; }
public float percentage { get; set; }
}
public class _45_601
{
public int goals { get; set; }
public float percentage { get; set; }
}
public class _60_751
{
public int goals { get; set; }
public float percentage { get; set; }
}
public class _75_901
{
public int goals { get; set; }
public float percentage { get; set; }
}
镜像
https://stackoverflow.com/questions/51012208
复制相似问题