[英]Cannot generate json class
I have this json
: 我有这个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
}
}
}
I'm trying to generate the class using this tool. 我正在尝试使用此工具生成类。 When I paste on that tool it say: 当我粘贴该工具时,它会说:
Parsing your JSON didn't work. 解析JSON不起作用。 Please make sure it's valid. 请确保它是有效的。
So I tried to check if this json is valid using this tool, and the json is valid, so why I cannot generate the c# class? 因此,我尝试使用此工具检查此json是否有效,并且json有效,那么为什么不能生成c#类?
If you're parsing the JSON
at runtime I recommend using NewtonSoft
nuget package. 如果您在运行时解析JSON
,则建议使用NewtonSoft
nuget包。 It's amazing and probably the most used. 这是惊人的,也许是最常用的。
If you want to copy and paste JSON
and make a class I recommend using Visual Studio to do this. 如果要复制和粘贴JSON
并创建一个类,我建议使用Visual Studio进行此操作。
Just copy the JSON
normally like a copy paste, open a class (or make a new class) in Visual Studio, then select 只需像复制粘贴一样复制JSON
,然后在Visual Studio中打开一个类(或创建一个新类),然后选择
Edit -> Paste Special -> Paste JSON as Classes 编辑->选择性粘贴->将JSON作为类粘贴
and it will turn it into the C# classes needed for you. 它将变成您需要的C#类。
Your JSON
above results in the following (that you can edit and modify as needed.) 上面的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; }
}
Image 图片
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.