我想知道我怎樣才能得到JSON響應的總和:總和嵌套的對象屬性的
我想獲得的交付總和所以這將是3435 + 20
{[
{
"date": "2016-10-01",
"stats": [
{
"type": "subuser",
"name": "[email protected]",
"metrics": {
"blocks": 23,
"bounce_drops": 164,
"bounces": 19,
"clicks": 0,
"deferred": 412,
"delivered": 3435,
"invalid_emails": 27,
"opens": 0,
"processed": 3481,
"requests": 3675,
"spam_report_drops": 3,
"spam_reports": 0,
"unique_clicks": 0,
"unique_opens": 0,
"unsubscribe_drops": 0,
"unsubscribes": 0
}
}
]
},
{
"date": "2016-10-02",
"stats": [
{
"type": "subuser",
"name": "[email protected]",
"metrics": {
"blocks": 0,
"bounce_drops": 0,
"bounces": 0,
"clicks": 0,
"deferred": 95,
"delivered": 20,
"invalid_emails": 0,
"opens": 0,
"processed": 0,
"requests": 0,
"spam_report_drops": 0,
"spam_reports": 0,
"unique_clicks": 0,
"unique_opens": 0,
"unsubscribe_drops": 0,
"unsubscribes": 0
}
}
]
}
]}
我會做這樣的事嗎?我曾嘗試這樣做,但它不工作,我會得到錯誤:
Additional information: Cannot perform runtime binding on a null reference
string getresponse;
getresponse = response.Body.ReadAsStringAsync().Result;
string s = getresponse;
dynamic o = JsonConvert.DeserializeObject(s);
textBox1.Text = o[0].stats[0].metrics[0].delivered;
'的問題o [0]'沒有'metrics'屬性。再看看你的結構。事實上,你甚至沒有有效的JSON開始。 –
@MattBurland不會是o [0] .stats [0] .metrics [0] .delivered; ?? –