我正在尝试解析以下的JSON数组:
[
{
"email": "john.doe@sendgrid.com",
"timestamp": 1337197600,
"smtp-id": "<4FB4041F.6080505@sendgrid.com>",
"event": "processed"
},
{
"email": "john.doe@sendgrid.com",
"timestamp": 1337966815,
"smtp-id": "<4FBFC0DD.5040601@sendgrid.com>",
"category": "newuser",
"event": "clicked"
},
{
"email": "john.doe@sendgrid.com",
"timestamp": 1337969592,
"smtp-id": "<20120525181309.C1A9B40405B3@Example-Mac.local>",
"event": "processed"
}
]
我以前没有真正使用过JSON格式,所以这对我来说都是新鲜事。我发现可以轻松解析单个元素,例如:
{
"email": "john.doe@sendgrid.com",
"timestamp": 1337197600,
"smtp-id": "<4FB4041F.6080505@sendgrid.com>",
"event": "processed"
}
dynamic stuff = JsonConvert.DeserializeObject(json);
Response.Write(string.Format("{0} = {1}<br />", "timestamp", stuff.timestamp));
//etc
但我不知道如何将单个元素放入数组中进行循环遍历。
我考虑过在},{上分割字符串,但没有成功。我想可能有更简单的方法,但我没有找到。
谢谢。
stuff[i].timestamp
。 - L.B