Fehler beim Deserialisieren eines JSON-Textes in ein C#-ModellC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Fehler beim Deserialisieren eines JSON-Textes in ein C#-Modell

Post by Anonymous »

Ich habe eine API, die die JSON-Daten im folgenden Format zurückgibt

Code: Select all

[
{
"@type": "https://XXXXXX.com/model/portfolio-mgmt/positions/Positions.v1.json#/Position",
"assetId": "GGG4H1L19",
"parentAssetId": "GGG4H1L19",
"ccy": "USD",
"strategyId": 0,
"strategyName": "Unassigned2",
"price": 94.030073,
"pricePurpose": "SSB",
"priceSource": "MT535",
"priceDate": "2025-12-18",
"riskDate": "2025-12-18",
"secGroup": "BND",
"secType": "CORP",
"secDesc1": "DFGFGFGF (DFGFGFGF FF)",
"secDesc2": "",
"cpn": 5.25,
"isin": "XS1936302949",
"sedol": "JJJ66T4",
"posSource": "EOD",
"factor": 1,
"factorDate": "2019-01-16T08:00:00.000Z",
"tradeTranType": "",
"baseCcy": "USD",
"accrualDays": 0,
"accruedInterest": 2.216666666666667,
"dts": 2024.1029242285342,
"krd10y": 1.2935621721818327,
"krd15y": 1.7085157867230247,
"krd20y": 2.6932766823014798,
"krd25y": 5.457588395021552,
"krd30y": 0,
"krd1y": 0.04808081621919099,
"krd2y": 0.09692890561954999,
"krd3m": 0.010833756764871999,
"krd3y": 0.22853401741634796,
"krd40y": 0,
"krd50y": 0,
"krd5y": 0.41955447649324296,
"krd7y": 0.6790998761984979,
"market": "EURO",
"marketRegion": "",
"modDur": 12.925992851114477,
"modDurToWorst": 12.925992851114477,
"oad": 12.635974884939591,
"oac": 2.366394844562937,
"staticYield": 5.708861963822853,
"walToWorst": 24.077777777777776,
"oas": 92.0086199143619,
"portfolioNAV": 2825896822.787146,
"priceAssetId": "GGG4H1L19",
"priceIssue": 98.614,
"spreadDur": 12.933009087897315,
"wal": 24.077777777777776,
"issuerCountry": "DFGFGFGF",
"mktValueSOD": 384986.9586666667,
"notionalMktValueSOD": 384986.9586666667,
"priceDateSOD": "2025-12-18",
"pricePurposeSOD": "SSB",
"priceSOD": 94.030073,
"priceSourceSOD": "MT535",
"riskSource": "LEH",
"ultimateIssuerShortName": "DFGFGFGF DFGFGFGF FF (GOVERNMENT)",
"ultimateIssuerLongName": "DFGFGFGF DFGFGFGF FF (GOVERNMENT)",
"ultimateIssuerTicker": "DDD",
"countryRisk": "DFGFGFGF",
"issuerId": "R84549",
"issuerLongName": "DFGFGFGF Generic OF (GOVERNMENT)",
"issuerShortName": "DFGFGFGF Generic OF (GOVERNMENT)",
"issuerTicker": "DDD",
"mktValue": 384986.9586666667,
"notionalMktValue": 384986.9586666667,
"portfolioName": "HHHHH",
"posQuantity": 400000,
"priceAsPct": true,
"putCallType": "NONE",
"secTicker": "DDD",
"ultimateParentIssuerId": "R84549",
"maturity": "2050-01-16",
"minTradeIncrement": 1000,
"minTradeSize": 200000,
"referenceDate": "2025-12-18",
"cashComputed": 0,
"portfolioNAVComputed": 2827824599.9418983,
"portfolioNAVComputedNotional": 2827824599.941902,
"currentFaceSOD": 400000,
"qtySOD": 400000,
"localBaseFxRate":  1,
"isRateFlipped": true,
"gpStatus": "Best Available",
"inflationDuration": 0,
"alternateOas": 156.50672712529723,
"parentCurrencySwapAssetId": ""
},
{
"@type": "https://XXXXXX.com/model/portfolio-mgmt/positions/Positions.v1.json#/Position",
"assetId": "XXXXXXXXXX",
"parentAssetId": "XXXXXXXXXX",
"ccy": "USD",
"strategyId": 0,
"strategyName": "Unassigned2",
"price": 102.216194,
"pricePurpose": "CCCC",
"priceSource": "VT535",
"priceDate": "2025-12-18",
"riskDate": "2025-12-18",
"secGroup": "CCC",
"secType": "CORP",
"secDesc1": "JJJ XXXX VVVV LLC",
"secDesc2": "",
"cpn": 8.125,
"isin": "TY86177CAA71",
"sedol": "SDFSDFSD7",
"posSource": "EOD",
"factor": 1,
"factorDate": "2025-11-21T08:00:00.000Z",
"tradeTranType": "",
"baseCcy": "USD",
"accrualDays": 0,
"accruedInterest": 0.609375,
"dts": 1382.2655872780178,
"krd10y": 0,
"krd15y": 0,
"krd20y": 0,
"krd25y": 0,
"krd30y": 0,
"krd1y": 0.06832427405840302,
"krd2y": 0.22074179211052408,
"krd3m": 0.013892238553316005,
"krd3y": 0.9288834301391363,
"krd40y": 0,
"krd50y": 0,
"krd5y": 2.334211165498947,
"krd7y": 0.008873766119436003,
"market": "United States",
"marketRegion": "North America",
"modDur": 4.037147441353961,
"modDurToWorst": 3.351927550957375,
"oad": 3.574926666479762,
"oac": -0.213010269605084,
"staticYield": 7.466725507621863,
"walToWorst": 3.991666666666667,
"oas": 362.7412058298751,
"portfolioNAV": 2825896822.787146,
"priceAssetId": "86177CAA7",
"priceIssue": 100,
"spreadDur": 3.573065145754676,
"wal": 3.991666666666667,
"issuerCountry": "United States",
"mktValueSOD": 102825.569,
"notionalMktValueSOD": 102825.569,
"priceDateSOD": "2025-12-18",
"pricePurposeSOD": "FFF",
"priceSOD": 102.216194,
"priceSourceSOD": "MT535",
"riskSource": "LEH",
"ultimateIssuerShortName": "JJJ XXXX VVVV LLC",
"ultimateIssuerLongName": "JJJ XXXX VVVV LLC",
"ultimateIssuerTicker": "GHGHGB",
"countryRisk": "United States",
"issuerId": "P04147",
"issuerLongName": "JJJ XXXX VVVV LLC",
"issuerShortName": "JJJ XXXX VVVV LLC",
"issuerTicker": "GHGHGB",
"mktValue": 102825.569,
"notionalMktValue": 102825.569,
"portfolioName": "HHHHH",
"posQuantity": 100000,
"priceAsPct": true,
"putCallType": "CALL",
"secTicker": "GHGHGB",
"ultimateParentIssuerId": "Y787147",
"maturity": "2030-12-15",
"minTradeIncrement": 1000,
"minTradeSize": 1000,
"referenceDate": "2025-12-18",
"cashComputed": 0,
"portfolioNAVComputed": 2827824599.9418983,
"portfolioNAVComputedNotional": 2827824599.941902,
"currentFaceSOD":  100000,
"qtySOD": 100000,
"localBaseFxRate": 1,
"isRateFlipped": true,
"gpStatus": "Best Available",
"inflationDuration": 0,
"alternateOas": 386.8570907307278,
"parentCurrencySwapAssetId": ""
},
{
"@type": "https://XXXXXX.com/model/portfolio-mgmt/positions/Positions.v1.json#/Position",
"assetId": "GGG5FR0P1",
"parentAssetId": "GGG5FR0P1",
"ccy": "USD",
"strategyId": 0,
"strategyName": "Unassigned2",
"price": 97.224091,
"pricePurpose": "HHHHH",
"priceSource": "YU535",
"priceDate": "2025-12-18",
"riskDate": "2025-12-18",
"secGroup": "VVV",
"secType": "CORP",
"secDesc1": "GGGGGG (Generic OF)",
"secDesc2": "",
"cpn": 5.45,
"isin": "XS2226916216",
"sedol": "GHGPBC7",
"posSource": "EOD",
"factor": 1,
"factorDate": "2020-09-16T07:00:00.000Z",
"tradeTranType": "",
"baseCcy": "USD",
"accrualDays": 0,
"accruedInterest": 1.392777777777778,
"dts": 1333.3118177314327,
"krd10y": 0,
"krd15y": 0,
"krd20y": 0,
"krd25y": 0,
"krd30y": 0,
"krd1y": 0.047633324734842004,
"krd2y": 0.09631934969371302,
"krd3m": 0.013040436161854001,
"krd3y": 0.22399326838411102,
"krd40y": 0,
"krd50y": 0,
"krd5y": 0.9384728704083761,
"krd7y": 4.207453444191736,
"market": "EURO",
"marketRegion": "",
"modDur": 5.474656371794106,
"modDurToWorst": 5.474656371794106,
"oad": 5.526912693574632,
"oac": 0.37031729208423,
"staticYield": 5.953934833241181,
"walToWorst": 6.744444444444445,
"oas": 206.59405653127104,
"portfolioNAV": 2825896822.787146,
"priceAssetId": "HHHH5FR0P1",
"priceIssue": 0,
"spreadDur": 5.632744411334639,
"wal": 6.744444444444445,
"issuerCountry": "Some Country",
"mktValueSOD": 197233.73755555556,
"notionalMktValueSOD": 197233.73755555556,
"priceDateSOD": "2025-12-18",
"pricePurposeSOD": "Some",
"priceSOD": 97.224091,
"priceSourceSOD": "Some535",
"riskSource": "Some",
"ultimateIssuerShortName": "Some Country (Generic OF)",
"ultimateIssuerLongName": "Some Country (Generic OF)",
"ultimateIssuerTicker": "Some Country",
"countryRisk": "Some Country",
"issuerId": "R75070",
"issuerLongName": "Some Country (Generic OF)",
"issuerShortName": "Some Country (Generic OF)",
"issuerTicker": "Some Country",
"mktValue": 197233.73755555556,
"notionalMktValue": 197233.73755555556,
"portfolioName": "HHHHH",
"posQuantity": 200000,
"priceAsPct": true,
"putCallType": "NONE",
"secTicker": "Some Country",
"ultimateParentIssuerId": "R75070",
"maturity": "2032-09-16",
"minTradeIncrement": 1000,
"minTradeSize": 200000,
"referenceDate": "2025-12-18",
"cashComputed": 0,
"portfolioNAVComputed":  2827824599.9418983,
"portfolioNAVComputedNotional": 2827824599.941902,
"currentFaceSOD": 200000,
"qtySOD": 200000,
"localBaseFxRate": 1,
"isRateFlipped": true,
"gpStatus": "Best Available",
"inflationDuration": 0,
"alternateOas": 236.70731713806165,
"parentCurrencySwapAssetId": ""
}
]
Ich habe eine C#-Klasse für Model

Code: Select all

public class Position
{
public Dictionary? assetData { get; set; }
}
public class AssetData
{
[JsonPropertyName("assetId")]
public string? AssetID { get; set; }

//[JsonPropertyName("cusip2Set")]
//public Cusip2Set? Cusip2Set { get; set; }

//[JsonPropertyName("cusip")]
//public string? Cusip { get; set; }

[JsonPropertyName("secDesc1")]
public string? SecurityDescription { get; set; }

[JsonPropertyName("sedol")]
public string? Sedol { get; set; }

[JsonPropertyName("secTicker")]
public string? secTicker { get; set; }

[JsonPropertyName("isin")]
public string? isin { get; set; }

[JsonPropertyName("secType")]
public string? secType { get; set; }
}
Ich versuche, es mit dem folgenden Code zu deserialisieren

Code: Select all

var obj = JsonSerializer.Deserialize
(responseContent, SingletonJsonSerializerOptions.s_readOptions);
Kann mir bitte jemand helfen, warum es fehlschlägt und die Deserialisierung nicht möglich ist? Es wird mir ein sehr allgemeiner Fehler angezeigt, der Fehler ist wie folgt. Bitte helfen Sie mir, den kommenden JSON in die Positionsklasse oder das AssetData Dictionary zu deserialisieren. Jede Hilfe wäre sehr hilfreich, vielen Dank im Voraus.

Code: Select all

The JSON value could not be converted to CalSTRS.Aladdin.APICore.Models.BlackRock.Positions.AssetData. Path: $ | LineNumber: 0 | BytePositionInLine: 1.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post