【发布时间】:2014-02-23 20:23:28
【问题描述】:
我正在尝试解析以下 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 是一个数组。使用
stuff[i].timestamp