I dont have any problems but i don't know how API call data Nested Values
My Web API have Controller, Models and DataAccess that i call by use sql to call data
I want API call JSON Data format similar as below :
[
{
"Agent_Code": "123456",
"Name": "Miss Sara Manger",
"NickName": "Sara",
"BirthDay": "19690825",
"CardID": "9999999999",
"Address": "870 Goldleaf Lane Lyndhurst NJ New Jersey 07071",
"Mobile": "000000000",
"Email": "[email protected]",
"Bank": [
{
"AcctName": "Miss Sara Manger",
"Acctno": "9999999999",
"Bank": "KBANK"
}
]
}
]
Controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace Testdata.APIs
{
public class DashController : BaseApiController
{
[HttpPost]
public List<Models.AgentDto> TestJSON(Models.CountDashReq model)
{
DataAccess.DashDAL dal = new DataAccess.DashDAL();
List<Models.AgentDto> models = dal.TestJSON(model);
return models;
}
}
Model AgentDto And BankDto:
public class AgentDto
{
public string Agent_Code { get; set; }
public string Name { get; set; }
public string NickName { get; set; }
public string BirthDay { get; set; }
public string CardID { get; set; }
public string Address { get; set; }
public string Mobile { get; set; }
public string Email { get; set; }
public string Bank { get; set; }
}
public class BankDto
{
public string AcctName { get; set; }
public string Acctno { get; set; }
public string Bank { get; set; }
}
DataAccess:
public List<Models.AgentDto> TestJSON(Models.CountDashReq model)
{
string sql = "[dbo].[tb_Json_Get]";
List<Models.AgentDto> result = new List<Models.AgentDto>();
if (model != null)
{
List<SqlParameter> reqParam = new List<SqlParameter>();
//reqParam.Add(new SqlParameter("@usrLogin", model.usrLogin));
DataSet ds = this.Execute(sql, CommandType.StoredProcedure, reqParam.ToArray(), false);
if (ds.Tables.Count > 0)
{
foreach (DataRow row in ds.Tables[0].Rows)
{
Models.AgentDto paramslist = DataAccessUtility.DataTableExtensions.AsEnumerable<Models.AgentDto>(row);
result.Add(paramslist);
}
}
}
return result;
}
Please help me to use Case-when Thank you very much
If you getting request JSON as:
[
{
"Agent_Code": "123456",
"Name": "Miss Sara Manger",
"NickName": "Sara",
"BirthDay": "19690825",
"CardID": "9999999999",
"Address": "870 Goldleaf Lane Lyndhurst NJ New Jersey 07071",
"Mobile": "000000000",
"Email": "[email protected]",
"Bank": [
{
"AcctName": "Miss Sara Manger",
"Acctno": "9999999999",
"Bank": "KBANK"
}
]
}
]
Then the CountDashReq
class should be:
public class Bank
{
public string AcctName { get; set; }
public string Acctno { get; set; }
public string Bank { get; set; }
}
public class CountDashReq
{
public string Agent_Code { get; set; }
public string Name { get; set; }
public string NickName { get; set; }
public string BirthDay { get; set; }
public string CardID { get; set; }
public string Address { get; set; }
public string Mobile { get; set; }
public string Email { get; set; }
public List<Bank> Bank { get; set; }
}
In controller method:
[HttpPost]
public List<Models.AgentDto> TestJSON(IList<Models.CountDashReq> model)
{
// Your code
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加