我正在尝试编写 .net c# 代码来读取调用的结果campaignEmailStatsAIMAll()
。
这是我得到的 JSON 结果示例:
{
"total":3,
"data":{
"some...@company.com":[
{
"action":"click",
"timestamp":"2012-10-18 20:55:52",
"url":"http:\/\/www.someurl.com?ct=t(First_Chimp_Test10_18_2012)",
"ip":"66.66.666.666"
},
{
"action":"open",
"timestamp":"2012-10-18 20:55:52",
"url":null,
"ip":"66.66.666.666"
}
],
"anothe...@corporation.com":[
{
"action":"open",
"timestamp":"2012-10-18 20:18:05",
"url":null,
"ip":"22.222.222.222"
},
{
"action":"open",
"timestamp":"2012-10-18 20:18:18",
"url":null,
"ip":"22.222.222.222"
},
{
"action":"click",
"timestamp":"2012-10-18 20:18:18",
"url":"http:\/\/www.someurl.com?ct=t(First_Chimp_Test10_18_2012)",
"ip":"22.222.222.222"
},
{
"action":"click",
"timestamp":"2012-10-18 20:21:57",
"url":"http:\/\/www.someurl.com?ct=t(First_Chimp_Test10_18_2012)",
"ip":"22.222.222.222"
}
],
"thir...@business.com":[
]
}
}
我遇到的问题是如何定义 C# 对象来接受这个 JSON 字符串。电子邮件地址被视为 JSON 名称/值对的名称部分。我知道 .NET 有 3rd 方包装器,但我只想调用这个 API(可能还有其他几个)并且更愿意自己编写代码。我希望能够遍历对象以提取电子邮件地址,然后为每个对象提取操作/时间戳/url。
当我将这个 JSON 放到 json2sharp.com 的对象创建器中时,我得到了这个:
public class SomebodyCompanyCom {
public string action { get; set; }
public string timestamp { get; set; }
public string url { get; set; }
public string ip { get; set; }
}
public class AnotherpersonCorporationCom {
public string action { get; set; }
public string timestamp { get; set; }
public string url { get; set; }
public string ip { get; set; }
}
public class Data {
public List<SomebodyCompanyCom> __invalid_name__somebody@company.com { get; set; }
public List<AnotherpersonCorporationCom> __invalid_name__anotherperson@corporation.com { get; set; }
public List<object> __invalid_name__thirdguy@business.com { get; set; }
}
public class RootObject {
public int total { get; set; }
public Data data { get; set; }
}