简体   繁体   English

jObject属性的索引不起作用c#

[英]index for jObject properties not working c#

I am parsing a Bitcoin transaction String into a JObject (it is in JSON format) and want to reference the prev_out hash and second value in the JSON String (see below for an example). 我正在将比特币事务String解析为JObject (它是JSON格式)并且想要在JSON字符串中引用prev_out哈希值和第二个值(请参阅下面的示例)。 As you can see below I have tried to get the property values using the index but I keep getting null back. 正如你在下面看到的,我试图使用索引获取属性值,但我一直得到null Please help! 请帮忙!

What the Typical JSON string looks like: 典型的JSON字符串是什么样的:

{
    "hash" : "4ebf7f7ca0a5dafd10b9bd74d8cb93a6eb0831bcb637fec8e8aabf842f1c2688",
    "ver" : 1,
    "vin_sz" : 1,
    "vout_sz" : 2,
    "lock_time" : 0,
    "size" : 225,
    "in" : [{
            "prev_out" : {
                "hash" : "bf7d91ac70917f98b497927e1b07267507652b206df14ecdba2e9390b9bffc65",
                "n" : 0
            },
            "scriptSig" :
            "                               3044022069b6b0f1a8d453bdb89e3ad475232b8e01d2851e7b53acab3f830f40e80b3b5102203c0   49
                    867975360020293c735d48b4a2dda003aa781c1d8ccd2c7af290dcd11de01
                    02e3538427350039e67ea99e935cefb740badf3d09ebc301b0bc9d1bb0301a3417"
        }
    ],
    "out" : [{
            "value" : "0.08990000",
            "scriptPubKey" : "OP_DUP OP_HASH160 5b1d720daf0e95e37d0eaedd282b6ed9a40bab71
                     OP_EQUALVERIFY OP_CHECKSIG"
        }, {
            "value" : "0.01000000",
            "scriptPubKey" : "OP_DUP OP_HASH160 71049fd47ba2107db70d53b127cae4ff0a37b4ab
                    OP_EQUALVERIFY OP_CHECKSIG"
        }
    ]
}

I am trying to reference the prev_out hash value using this: 我试图使用这个引用prev_out哈希值:

JObject transaction = JObject.Parse(t1);
var d = transaction["in"][0]["hash"];

Where t1 is the JSON transaction string 其中t1是JSON事务字符串

I try to get the second value property using this: 我尝试使用以下方法获取第二个value属性:

JObject v = JObject.Parse(t1);
var val = v["out"][1]; //second value starting from 0
value = val.ToString();

"hash" lives inside "prev_out", so you need to access it like this: “hash”存在于“prev_out”中,因此您需要像这样访问它:

var d = transaction["in"][0]["prev_out"]["hash"];

This becomes clear if you format the JSON. 如果格式化JSON,这一点就变得清晰了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM