反序列化json数据
问题描述:
I am new in json.
In my project i need to deserialize json data come from amazon service url .
this is my json format <a href="
https://s3.amazonaws.com/afb-ses/bounce.json">json list</a>
<pre lang="HTML">{"complaint@simulator.amazonses.com":{"time":"2018-01-02T20:45:46.650Z","type":"Complaint","bounceType":"null","bounceSubType":"null"},
"struax@afb.net":{"time":"2018-01-02T20:53:03.000Z","type":"Bounce","bounceType":"Permanent","bounceSubType":"Suppressed"},
"bounce-test@service.socketlabs.com":{"time":"2018-01-02T21:06:40.097Z","type":"Bounce","bounceType":"Permanent","bounceSubType":"Suppressed"},
"bounce@simulator.amazonses.com":{"time":"2018-01-02T21:08:02.000Z","type":"Bounce","bounceType":"Permanent","bounceSubType":"General"},
"jstrechay@afb.net":{"time":"2018-01-05T06:31:39.000Z","type":"Bounce","bounceType":"Permanent","bounceSubType":"General"},
"leematt45@hotmail.com":{"time":"2018-01-05T06:49:13.000Z","type":"Bounce","bounceType":"Permanent","bounceSubType":"Suppressed"},
"afbweb@afb.net":{"time":"2018-01-07T12:50:38.000Z","type":"Bounce","bounceType":"Transient","bounceSubType":"General"},
"rushjenacath@gmail.com":{"time":"2018-01-05T06:32:42.000Z","type":"Bounce","bounceType":"Permanent","bounceSubType":"Suppressed"},
"Kerryhoskins0925@gmaiil.com":{"time":"2018-01-02T09:18:20.000Z","type":"Bounce","bounceType":"Transient","bounceSubType":"General"}}
i需要在db中记录此记录,我的db表列是电子邮件,类型,时间,bounceType,bounceSubType。
i我不明白怎么做这个,这是我得到json json链接的链接了解详情
提前感谢
我尝试过的事情:
i need to ave this record in db and my db table column's are Email ,type, time,bounceType, bounceSubType.
i am not understand how to do this and this is the link where i get the json json link for details
thanks in advance
What I have tried:
this is i tried
<pre lang="c#"> using (WebClient wc = new WebClient())
{
var json = wc.DownloadString("https://s3.amazonaws.com/afb-ses/bounce.json");
string jsonData = JsonConvert.SerializeObject(json);
var _userin = JsonConvert.DeserializeObject(jsonData);
}
此代码中的
json采用树结构反序列化,但如何保存DB
in this code json is Deserialized with tree structure but how to save in DB
答
尝试
try
dynamic _userin = JsonConvert.DeserializeObject(json);
foreach (var item in _userin)
{
string name = item.Name;
string time = item.Value.time;
string type = item.Value.type;
string bounceType = item.Value.bounceType;
string bounceSubType = item.Value.bounceSubType;
}
这是获取值的方法之一,看看这个文章 [ ^ ],您将在C#JSON上找到很多
this is one of the method to get the values, have a look on this article [^] by Graeme, you wll find lot on C# JSON