如何从c#中的这种长JSON文件获取值当前我在c#中使用动态变量但是如果我需要最新的JSON事务它将无法工作,因为动态变量保持特定位置的值但其本地将在之后增加处理一个新的交易,我需要目的地标签,所以我该怎么做。
{
"result":"success",
"count":5,
"transactions":[
{
"hash":"866B841C8C3B2D840497679FAC45A7D4341E12056AAA53F67471CA1B955FB58E",
"ledger_index":37860930,
"date":"2018-04-10T12:35:32+00:00",
"tx":{
"TransactionType":"Payment",
"Flags":2147483648,
"SourceTag":0,
"Sequence":20,
"DestinationTag":0,
"LastLedgerSequence":37860958,
"Amount":"25000000",
"Fee":"12",
"SigningPubKey":"02917EB4353C539A2B0766EFAB1723E5BB744516C673FFCF21457DAD44BCECFE25",
"TxnSignature":"304402202FA9FF18A572ACA1735B54CF5A69E10398EAF7003F3573E402ABA09B404F765C0220773481B494A941CC0F5338836A6B71F5FA2499943C41D50205C8EF158651BD86",
"Account":"rLcqTPYFSJBWGmu2ZXh8JTYGgdXRPjWTrx",
"Destination":"rfginNsDts73fZtzp858dT6Y6U67Y1QB7GV"
},
"meta":{
"TransactionIndex":1,
"AffectedNodes":[
{
"CreatedNode":{
"LedgerEntryType":"AccountRoot",
"LedgerIndex":"1C75CD43D75614E00025102355ADCCCF6302FAD5B82DC85F5AAF5696E4E39EC4",
"NewFields":{
"Sequence":1,
"Balance":"25000000",
"Account":"rfginNsDt73fZtzp858dT6Y6U6s7Y1QB7GV"
}
}
},
{
"ModifiedNode":{
"LedgerEntryType":"AccountRoot",
"PreviousTxnLgrSeq":37757840,
"PreviousTxnID":"C794D81D17DF1EA735200E50B9CEADDF19160841E1321F08FDB7C7C4D6BC41AF",
"LedgerIndex":"BE486CB1FED1B1805E4C42E8E96C73CFDA4E520C66BACEBBE441C1F8212D980E",
"PreviousFields":{
"Sequence":20,
"Balance":"537421240"
},
"FinalFields":{
"Flags":0,
"Sequence":21,
"OwnerCount":0,
"Balance":"512421228",
"Account":"rLcqTPYFSJBWGmu2ZXh8JTYGgdXRPjWTrx"
}
}
}
],
"TransactionResult":"tesSUCCESS",
"delivered_amount":"25000000"
}
},
{
"hash":"86E5D976DDCBF97047C86996286751B23C4384A8B4F6A04E38A57F30F54749CC",
"ledger_index":38906860,
"date":"2018-05-25T10:04:22+00:00",
"tx":{
"TransactionType":"Payment",
"Flags":2147483648,
"Sequence":28534,
"DestinationTag":2150,
"Amount":"25000000",
"Fee":"45",
"SigningPubKey":"",
"Account":"rG2uw1W9FXoiY4QiNqej5WeRxnoBEw4JbL",
"Destination":"rfginNsDt73fZtzp858dT6Y6U67Y1QB7GV",
"Signers":[
{
"Signer":{
"SigningPubKey":"032DCABB7A17A96E826435B461E474CB33C86C98B2281D304367FCFC6DE463A215",
"TxnSignature":"3045022100F9802AE2F7800D42233A5B63999C0BD7AE5B7D60D8244C949FF81EA39959B4BC02205E37DD331ACE2637F2BEE758B5AD642D259F4140E8DE53EF610B6F58745BCC05",
"Account":"rDc4zYyxMbXfUXNKw6zfM88RBUd9y8uPYX"
}
},
{
"Signer":{
"SigningPubKey":"03019752C3ABCB2BC89EC5FAEF55D72AE940820A30FBA079D2BB8CE8841174EF21",
"TxnSignature":"30450221009C7F9519912D494C9F009130927E1248BE6C2F877B1A913B49B8BFD926442F6802205377D1D242D07033DC6FDA8C93BC65638D636A87539F32A0D269AA9B537FCB0D",
"Account":"rKB5N7FxvcwHSYq4NCKjyMpjML1MznMrFc"
}
}
]
},
"meta":{
"TransactionIndex":17,
"AffectedNodes":[
{
"ModifiedNode":
答案 0 :(得分:0)
有一个叫做 Json.Net / Newtonsoft 的小块包,这个包有一些方法可以轻松地将json序列化和反序列化为类对象。
第1步:安装此模块> 安装包Newtonsoft.Json -Version 11.0.2
第2步:下一步是创建模仿完全相同json的类,所有键具有相同的名称,您可以使用名为选择性粘贴的功能这在Visual Studio中可用。
创建一个空类并将JSON复制到剪贴板,然后单击Edit>选择性粘贴> Json作为Class ,这将为您创建一个类,其结构与您的JSON相同。
第3步:使用以下代码将json反序列化为类对象,
JSONClass jsonObjectWithValue = JsonConvert.Deserialize<JSONClass>(jsonString)