JSON数组:
{ "statusCode": "01",
"data": {
"record":[
{ "id": "185633725", "betId": "6391509492", "username": "321967", "platType": "bg", "gameType": "1", "betAmount": "20.0000", "validAmount": "20.0000", "winLoss": "20.0000", "gameName": "百家乐", "betTime": "2020-05-04 19:33:16", "lastUpdateTime": "2020-05-04 19:33:29", "status": "1", "betContent": "下注闲赢", "awardResult": "" },
{ "id": "185634135", "betId": "6391515577", "username": "321967", "platType": "bg", "gameType": "1", "betAmount": "20.0000", "validAmount": "20.0000", "winLoss": "-20.0000", "gameName": "百家乐", "betTime": "2020-05-04 19:34:43", "lastUpdateTime": "2020-05-04 19:34:57", "status": "1", "betContent": "下注庄赢", "awardResult": "" },
{ "id": "185638575", "betId": "6391555491", "username": "321967", "platType": "bg", "gameType": "1", "betAmount": "20.0000", "validAmount": "20.0000", "winLoss": "-20.0000", "gameName": "百家乐", "betTime": "2020-05-04 19:44:34", "lastUpdateTime": "2020-05-04 19:44:48", "status": "1", "betContent": "下注庄赢", "awardResult": "" },
{ "id": "185639036", "betId": "6391557792", "username": "321967", "platType": "bg", "gameType": "1", "betAmount": "20.0000", "validAmount": "20.0000", "winLoss": "-20.0000", "gameName": "百家乐", "betTime": "2020-05-04 19:45:19", "lastUpdateTime": "2020-05-04 19:45:30", "status": "1", "betContent": "下注庄赢", "awardResult": "" }],
"currentPage": "1", "totalPage": "1", "countNum": "4" }, "message": "成功"} { "type": "alipay", "total": "100", "api_order_sn": "PDD20200430212539179", "notify_url": "http://47.92.96.33:7655/Pay/PingDD/Notify.aspx", "client_id": "7a37419f348b96ca3bd7bb7ead56380c", "tytimestamppe": "1588253139390", "sign": "B0E20F90E2827D5EACCC3A0D53E250EA"}
json数组是我从别的地方获取,需要插入到自己的数据库
引用:Newtonsoft.Json.Linq;
string jsonResponse = 以上json
//序列化json
JObject obj = Newtonsoft.Json.Linq.JObject.Parse(jsonResponse);
string RecordData = obj["data"]["record"].ToString();
JArray array = Newtonsoft.Json.Linq.JArray.Parse(RecordData);
//初始sql语句
string sql = " INSERT INTO VideoRecordInfo(id,betId,username,platType,gameType,betAmount,validAmount,winLoss,gameName,betContent,awardResult,betTime,lastUpdateTime,status) VALUES";
foreach (var ss in array ) //遍历JArray 数组
{
string id = ss["id"].ToString();
string betId = ss["betId"].ToString();
string username = ss["username"].ToString();
string platType = ss["platType"].ToString();
string gameType = ss["gameType"].ToString();
string betAmount = ss["betAmount"].ToString();
string validAmount = ss["validAmount"].ToString();
string winLoss = ss["winLoss"].ToString();
string gameName = ss["gameName"].ToString();
string betContent = ss["betContent"].ToString();
string awardResult = ss["awardResult"].ToString();
string betTime = ss["betTime"].ToString();
string lastUpdateTime = ss["lastUpdateTime"].ToString();
string status = ss["status"].ToString();
//判断是否是最后一条数据
if (ss == array[array.Count() - 1])
{
sql += "('" + id + "','" + betId + "','" + username + "','" + platType + "','" + gameType + "','" + betAmount + "','" + validAmount + "','" + winLoss + "','" + gameName + "','" + betContent + "','" + awardResult + "','" + betTime + "','" + lastUpdateTime + "','" + status + "')";
}
else
{
sql += "('" + id + "','" + betId + "','" + username + "','" + platType + "','" + gameType + "','" + betAmount + "','" + validAmount + "','" + winLoss + "','" + gameName + "','" + betContent + "','" + awardResult + "','" + betTime + "','" + lastUpdateTime + "','" + status + "'),";
}
}
int y = DBRecordBLL.InsertRecord(sql);//插入数据库