我正在将比特币事务字符串解析为JObject(它是
JSON格式)并且想要在
JSON字符串中引用prev_out哈希值和第二个值(请参阅下面的示例).正如你在下面看到的,我试图使用索引获取属性值,但我一直得到null.请帮忙!
典型的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"
}
]
}
我试图使用这个引用prev_out哈希值:
JObject transaction = JObject.Parse(t1);
var d = transaction["in"][0]["hash"];
其中t1是JSON事务字符串
我尝试使用以下方法获取第二个值属性:
JObject v = JObject.Parse(t1);
var val = v["out"][1]; //second value starting from 0
value = val.ToString();
最佳答案 “hash”存在于“prev_out”中,因此您需要像这样访问它:
var d = transaction["in"][0]["prev_out"]["hash"];
如果格式化JSON,这一点就变得清晰了.