TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ankit Yadav
NA
762
38.9k
How to passt Json Object list as a parameter in Web API
May 28 2019 2:59 AM
Hey Guys ,
I have made an api which receives the list of the object as a paramers but the andoid developer need to pass that list as json list array , now when i pass the list as the model that i have made for the web apllication then i receive the list as null , and when i pass the same request after making another model (json to c#)with same fileds and datatypes i get the list of the model.
public
class
GroundWaterScheduleFormModel
//Model for Web Application
{
public
int
id { get; set; }
public
int
RowNum { get; set; }
public
int
? zoneId { get; set; }
public
string stateName { get; set; }
public
int
? stateCode { get; set; }
public
string dateOfCensus { get; set; }
public
string districtName { get; set; }
public
int
? districtCode { get; set; }
public
string blockName { get; set; }
public
int
? blockCode { get; set; }
public
string villageName { get; set; }
public
int
? villageCode { get; set; }
public
int
SchemeSrNo { get; set; }
public
int
? schemeType { get; set; }
public
int
? typeOfDugWell { get; set; }
//public int typeOfDugWell { get; set; }
public
int
? typeOfTubeWell { get; set; }
public
class
InsertGWList
{
public
List
GWFormList { get; set; }
}
[Route(
"GroundWater/InsertGWDetails"
)]
public
HttpResponseMessage InsertGWMultiDetails([FromBody] InsertGWMultiList model)
{
try
{
}
catch
(Exception ex)
{
throw
ex;
}
}
{
"data"
: [{
"id"
: 794,
"RowNum"
: 0,
"zoneId"
:
null
,
"stateName"
:
null
,
"stateCode"
:
null
,
"dateOfCensus"
:
null
,
"districtName"
:
"Ahmedabad"
,
"districtCode"
: 438,
"blockName"
:
"DHOLKA"
,
"blockCode"
: 438006,
"villageName"
:
"AMBARELI"
,
"villageCode"
: 238266,
"SchemeSrNo"
: 45,
"schemeType"
: 2,
"typeOfDugWell"
: 0,
"typeOfTubeWell"
: 2
}]
now when i pass
above request as parameter then i get the null in InsertGWMultiListmodel , SO i have coverted this request into Json2charpe converted and pass that model as a paramerter .
public
class
GWDetail
//Model for android Application
{
public
int
id {
get
;
set
; }
public
int
RowNum {
get
;
set
; }
public
object
zoneId {
get
;
set
; }
public
object
stateName {
get
;
set
; }
public
object
stateCode {
get
;
set
; }
public
object
dateOfCensus {
get
;
set
; }
public
string
districtName {
get
;
set
; }
public
int
districtCode {
get
;
set
; }
public
string
blockName {
get
;
set
; }
public
int
blockCode {
get
;
set
; }
public
string
villageName {
get
;
set
; }
public
int
villageCode {
get
;
set
; }
public
int
SchemeSrNo {
get
;
set
; }
public
int
schemeType {
get
;
set
; }
public
int
typeOfDugWell {
get
;
set
; }
public
int
typeOfTubeWell {
get
;
set
; }
}
public
class
GWDetailList
{
public
List
data {
get
;
set
; }
}
}
i am calling the api by passing
GWDetailList as paramerter and i am getting the list , so my question is I dont want to creat two model for the same purpose & why i not getting the list of object in
InsertGWMultiList.
[Route(
"GroundWater/InsertGWDetails"
)]
public
HttpResponseMessage InsertGWMultiDetails([FromBody] GWDetailList model)
{
try
{
}
catch
(Exception ex)
{
throw
ex;
}
}
Reply
Answers (
1
)
How to Call Python Batch File From Controller in MVC Project
Gridview webhsop