我正在尝试反序列化Json对象并且它向我抛出错误无法转换类型' Newtonsoft.Json.Linq.JObject'输入' Newtonsoft.Json.Linq.JArray'。
错误肯定是下面添加的新片段,它正确地反序列化。我认为它可能是StressTestResults,它具有键值对值,可能不是数组。
New Json补充说导致上面的错误
{
"StressTestAnalysis":{
"StressTestResults": {
"curlevel":0,
"decrease":0,
"increase":0
},
"StressTestGraphData": {
"yaxis": [
1000000,
1500000,
2000000,
2500000,
3000000,
14000000
],
"data": [
20.00,
18.18,
16.53,
15.03,
13.66,
12.42,
11.29,
10.26,
1.68
]
}
}
}
完成Json
{
"NpvResults":{
"CommIns":[
[
-4137.0277805691812,
82.740555611385162,
1,
-4054.2872249578099
],
[
-4137.0277805691812,
82.740555611385162,
2,
-4054.2872249578099
],
[
-4137.0277805691812,
82.740555611385162,
3,
-4054.2872249578099
],
[
-4137.0277805691812,
82.740555611385162,
4,
-4054.2872249578099
],
[
-4137.0277805691812,
82.740555611385162,
5,
-4054.2872249578099
]
],
"CaptiveIns":[
[
-4221.4569189482418,
84.429138378963501,
22.710059979002764,
-0.019802950859533291,
0,
0,
1,
-4114.337523541084
],
[
-4221.4569189482418,
84.429138378963501,
22.752243205547771,
0,
0,
0,
2,
-4114.275537363681
],
[
-4221.4569189482418,
84.429138378963501,
22.749463056422599,
0,
0,
0,
3,
-4114.2783175128006
],
[
-4221.4569189482418,
84.429138378963501,
22.829863952642476,
0,
0,
0,
4,
-4114.1979166165802
],
[
-4221.4569189482418,
84.429138378963501,
22.813678007288622,
0,
0,
0,
5,
-4114.2141025619358
],
[
0,
0,
0,
0,
0,
0,
6,
0
]
],
"SelfIns":[
[
-18.283680484373004,
0.36567360968745993,
1,
-17.918006874685538
],
[
-17.950738378065587,
0.35901476756131162,
2,
-17.59172361050425
],
[
-17.528414768410823,
0.35056829536821654,
3,
-17.177846473042624
],
[
-17.199888318302875,
0.343997766366058,
4,
-16.855890551936845
],
[
-16.962838081589766,
0.33925676163179552,
5,
-16.623581319957964
]
],
"GraphData":[
[
-20271.436124789201,
-20271.436124789201,
-20271.436124789201,
-20271.436124789201,
-20271.436124789201
],
[
-20575.839967122232,
-20573.231848189709,
-20571.270058283782,
-20569.376102934919,
-20567.025718278568
],
[
-149.31279568973736,
-116.11250599884572,
-85.587513928638344,
-55.97322678189083,
-26.126318881224275
]
],
"LowestCost":[
{
"options":"CommIns",
"prob":0
},
{
"options":"CaptiveIns",
"prob":1
},
{
"options":"SelfIns",
"prob":0
}
]
},
"EvaResults":{
"CaptiveView":[
[
1,
1004.6356155327186,
0.019999999999999664,
50231.780776636006
],
[
2,
1024.6444682949152,
1004.6556155327187,
1.0199087932436166
],
[
3,
1045.3665533832836,
2029.3000838276355,
0.51513987811914741
],
[
4,
1066.2458049620784,
3074.6666372109171,
0.34678575400775757
],
[
5,
1087.6618426753635,
4140.9124421729957,
0.26266321517513735
]
],
"ParentView":[
[
1,
-0.00040000000000000734,
7500,
-2000,
35000,
40499.999600000519,
0.019999999999999664,
2024999.9800000158
],
[
2,
-20.093112310654377,
7650,
-2060,
35000,
40569.906887689343,
1004.6556155327187,
40.382410074732441
],
[
3,
-40.586001676552755,
7803,
-2121.1999999999698,
35000,
40641.213998323416,
2029.3000838276355,
20.027338095426597
],
[
4,
-61.493332744218421,
7959.0599999998312,
-2183.6240000000166,
35000,
40713.94266725576,
3074.6666372109171,
13.241799735750419
],
[
5,
-82.81824884345987,
8118.241200000044,
-2247.2964800000163,
35000,
40788.126471156589,
4140.9124421729957,
9.8500647047036747
]
],
"GraphData":[
[
49809.117488777483,
50104.699097064135,
50235.788311093122,
50362.666684675249,
50684.163143253129
],
[
2025082.8666373945,
2025083.3307724716,
2025083.4888383881,
2025083.6416729619,
2025084.0321642612
]
],
"LowestCost":[
{
"options":"CaptiveView",
"prob":1
},
{
"options":"ParentView",
"prob":0
}
]
},
"EndingSurplusResults":{
"EndingSurplusData": {
"perc25":6583.7612487804181,
"perc50":7533.9888417518869,
"mean":7568.2880884950882,
"perc75":8491.6674708256032,
"perc90":9289.8510640642089,
"perc95":9610.0343551595361
},
"GraphData": [
8576.4652724267216,
9410.545525237445,
9571.0108458564246,
10038.966929461712,
9405.1536272893627,
10079.743965285403,
8393.2949227139325,
8908.5518442208522,
9293.0264829383468,
9722.8583794184997,
9141.0634609955559,
8364.1029286600969,
8502.6875425273283,
8976.167984801772,
7877.4787333027598,
8952.7424983933197,
9201.9696148434487,
8847.4973060152206,
9747.7562848962589,
8962.9037815079791,
9022.1384539308201,
5681.1573013298594
]
},
"FinancialStatements":{
"IncomeStatement":[
[
1,
4178.1932500000103,
85.269249999998678,
4263.4624999999414,
18.465612134335959,
50.173097169011001,
170.53849999999736,
3000,
1024.2852906966514,
0.85309250000000236,
-4642.3097170227602,
1025.138383196653,
-3617.171333826107,
20.502767663933046,
-72.343426676522142,
1004.6356155327186,
1004.6356155327186,
-92.84619434045527,
0.016099287680693068,
0.74365342723195738,
0.75975271491266771
],
[
2,
4261.7571149999503,
86.974635000000731,
4348.7317499999263,
18.491944231444947,
51.605102225783959,
173.94927000000146,
3060,
1044.6854335427724,
0.87014635000001883,
-4826.5589078423809,
1045.5555798927724,
-3781.0033279496056,
20.911111597855385,
-75.620066558992093,
1024.6444682949152,
1024.6444682949152,
-189.37737249730282,
0.016118963064858854,
0.74365342723195738,
0.75977239029683274
],
[
3,
4346.9922572999239,
88.714127700000333,
4435.7063850000332,
18.418025530043888,
52.847080670134723,
177.42825540000067,
3121.2000000000389,
1065.8130233998197,
0.88754127699999308,
-4893.8329583179911,
1066.7005646768214,
-3827.1323936411636,
21.334011293536406,
-76.542647872823409,
1045.3665533832836,
1045.3665533832836,
-287.25403166366249,
0.016066236133476294,
0.74365342723195738,
0.75971966336545038
],
[
4,
4433.932102446006,
90.488410253999461,
4524.4205127000223,
18.434282054184305,
54.284770809664288,
180.97682050799892,
3183.6239999999598,
1087.1006393281507,
0.90528410254000691,
-5189.5034432464236,
1088.0059234306907,
-4101.4975198157326,
21.760118468613825,
-82.029950396314604,
1066.2458049620784,
1066.2458049620784,
-391.04410052859066,
0.016072567229267684,
0.74365342723195738,
0.75972599446124212
],
[
5,
4522.610744494943,
92.298178459080859,
4614.9089229540396,
18.543823690342677,
55.536620991960014,
184.59635691816172,
3247.2964800000173,
1108.9356413535372,
0.92338178459078979,
-5236.1929873248337,
1109.8590231381279,
-4126.3339641867033,
22.197180462762532,
-82.526679283733927,
1087.6618426753635,
1087.6618426753635,
-495.76796027508777,
0.016052417484088474,
0.74365342723195738,
0.7597058447160624
]
],
"CashFlow":[
[
1,
4263.4624999999414,
18.465612134335959,
3000,
-72.343426676522142,
170.53849999999736,
1146.8018145421861,
-22.936036290843688,
0.85309250000000236,
0.019999999999999664,
1124.7388707513417,
0,
0
],
[
2,
4348.7317499999263,
18.491944231444947,
3060,
-75.620066558992093,
173.94927000000146,
1171.9106023275467,
-23.438212046550877,
0.87014635000001883,
0,
2274.081407382339,
1124.7388707513417,
0
],
[
3,
4435.7063850000332,
18.418025530043888,
3121.2000000000389,
-76.542647872823409,
177.42825540000067,
1195.20275194278,
-23.904055038855581,
0.88754127699999308,
0,
2321.5287748119181,
1149.3425366309982,
0
],
[
4,
4524.4205127000223,
18.434282054184305,
3183.6239999999598,
-82.029950396314604,
180.97682050799892,
1223.4153605341307,
-24.46830721068261,
0.90528410254000691,
0,
2372.0385756069109,
1172.1862381809224,
0
],
[
5,
4614.9089229540396,
18.543823690342677,
3247.2964800000173,
-82.526679283733927,
184.59635691816172,
1246.9989416292328,
-24.939978832584625,
0.92338178459078979,
0,
2422.8346820072279,
1199.8523374259858,
0
]
],
"BalanceSheet":[
[
1,
0.019999999999999664,
-92.84619434045527,
-22.936036290843688,
50.173097169011001,
1004.6356155327186,
0.019999999999999664,
835.63864999998646,
0,
0.019999999999999664,
1004.6556155327187,
0,
0,
1004.6756155327198,
1054.82871270173,
1124.7388707513417,
1101.8228344604984
],
[
2,
0.019999999999999664,
-189.37737249730282,
-46.37424833739469,
101.77819939479492,
1024.6444682949152,
0.019999999999999664,
852.35142299998779,
1004.6556155327187,
0,
2029.3000838276355,
0,
0,
2029.3200838276339,
2131.0782832224281,
2274.081407382339,
2227.7271590449436
],
[
3,
0.019999999999999664,
-287.25403166366249,
-70.278303376250193,
154.62528006492957,
1045.3665533832836,
0.019999999999999664,
869.39845145997833,
2029.3000838276355,
0,
3074.6666372109171,
0,
0,
3074.686637210918,
3229.2919172758507,
2321.5287748119181,
2251.2704714356696
],
[
4,
0.019999999999999664,
-391.04410052859066,
-94.746610586932803,
208.91005087459402,
1066.2458049620784,
0.019999999999999664,
886.78642048919619,
3074.6666372109171,
0,
4140.9124421729957,
0,
0,
4140.9324421729971,
4349.8224930475881,
2372.0385756069109,
2277.3119650199792
],
[
5,
0.019999999999999664,
-495.76796027508777,
-119.68658941951738,
264.44667186655391,
1087.6618426753635,
0.019999999999999664,
904.52214889900233,
4140.9124421729957,
0,
5228.5742848483651,
0,
0,
5228.5942848483655,
5493.0209567149213,
2422.8346820072279,
2303.1680925877076
]
]
},
"StressTestAnalysis":{
"StressTestResults": {
"curlevel":0,
"decrease":0,
"increase":0
},
"StressTestGraphData": {
"yaxis": [
1000000,
1500000,
2000000,
2500000,
3000000,
14000000
],
"data": [
20.00,
18.18,
16.53,
15.03,
13.66,
12.42,
1.68
]
}
},
"PackList":[
{
"tblname":"CommIns",
"cols":"premPaid;taxDeduction;year;netCostProj",
"Item":"NpvResults"
},
{
"tblname":"CaptiveIns",
"cols":"premPaid;taxDeduction;loanToParent;capContriDistr;dividendDistr;terminalVal;year;netCostProj",
"Item":"NpvResults"
},
{
"tblname":"SelfIns",
"cols":"discountedLossesPaid;discountedTaxDeduction;year;netCostProj",
"Item":"NpvResults"
},
{
"tblname":"GraphData",
"cols":"CommIns;CaptiveIns;SelfIns",
"Item":"NpvResults"
},
{
"tblname":"CaptiveView",
"cols":"year;captiveNetIncome;surplusDeployed;impliedRoi",
"Item":"EvaResults"
},
{
"tblname":"ParentView",
"cols":"year;costOfCapDeployed;costOfRiskArb;incrCost;npvTaxBenefit;outcome;surplusDeployed;impliedRoi",
"Item":"EvaResults"
},
{
"tblname":"GraphData",
"cols":"CaptiveView;ParentView",
"Item":"EvaResults"
},
{
"tblname":"IncomeStatement",
"cols":"year;directPremWritten;cededPremWritten;netPremWritten;lossesLaePaid;chgResIbnr;othrUwExp;gaExp;uwGain;netInvestmentIncome;irsDiscount;preTaxOpIncomeWithIrs;preTaxOpIncomeWithoutIrs;fedIncomeTaxWithIrs;fedIncomeTaxWithoutIrs;netOperatingIncome;netIncome;deferredTaxAssets;lossLaeRatio;expRatio;netCombinedRatio",
"Item":"FinancialStatements"
},
{
"tblname":"CashFlow",
"cols":"year;premCollected;lossLaePaid;gaExpPaid;fedIncomeTaxPaid;othrUwExpPaid;netCashByOpActivities;loanBack;invPurchasedSold;capPaidIn;cashInvEndOfYear;cashInvStartOfYear;dividendsPaid",
"Item":"FinancialStatements"
},
{
"tblname":"BalanceSheet",
"cols":"year;othrAssets;defFedIncTax;loanbackAsset;totLiabilities;retainedEarnings;nonControllingInt;capAdequacyReqd;capital;addnPaidInCap;shareholderEquity;additionallyNeeded;distribute;totShareholderEquity;totLiabilitiesTotShEquity;totCashInvestment;totAssets",
"Item":"FinancialStatements"
}
]
}
映射到Json的Trigger2Output类
[JsonConverter(typeof(MinifyingJsonConverter))]
public class StressTestAnaylsis
{
public StressTestResults StressTestResults { get; set; }
public StressTestGraphData StressTestGraphData { get; set; }
}
public class StressTestResults
{
[JsonMinify]
public double curlevel { get; set; }
[JsonMinify]
public double decrease { get; set; }
[JsonMinify]
public double increase { get; set; }
}
public class StressTestGraphData
{
[JsonMinify]
public List<int> yaxis { get; set; }
[JsonMinify]
public List<double> data { get; set; }
}
反序列化的方法
public void Trigger2_Output_Deserialize_JSON_Minified()
{
var json = File.ReadAllText("Models\\Trigger2OutputMinified.json");
var o = JObject.Parse(json);
var tmp = JsonConvert.DeserializeObject<Trigger2Output>(o.ToString());
}