简体   繁体   中英

Extracting json or object from POST

We have this data

models:"[{"timeTableId":5,"startTime":"2016-06-16T00:00:00","endTime":"2016-06-16T17:00:00","userId":31,"customerId":35}]"

being sent to a asp.net webservice using api.

We cannot determine how to extract the data for manipulation, we have tried...

public IHttpActionResult PostTimeTable([FromBody]string models);// models is null
public IHttpActionResult PostTimeTable(string models);// models is null
public IHttpActionResult PostTimeTable([FromBody]List<TimetableView> models);// models is null
public IHttpActionResult PostTimeTable(IEnumerable<TimetableView> models);// models is null

Where TimetableView is

public class TimetableView
    {

        public TimetableView(TimeTable timetable)
        {
            this.TimeTableId = timetable.TimeTableId;
            this.StartTime = timetable.StartTime;
            this.EndTime = timetable.EndTime;
            this.UserId = timetable.UserId;
            this.CustomerId = timetable.CustomerId  ;
        }

        public TimetableView(){}

        public int TimeTableId { get; set; }

        public DateTime StartTime { get; set; }

        public DateTime EndTime { get; set; }

        public int UserId { get; set; }
        public int CustomerId { get; set; }

    }

try this

public IHttpActionResult PostTimeTable(
       int timeTableId,
       DateTiem startTime,
       DateTime endTime,
       int userId,
       int customerId);

I have found out why this was not saving or getting the correct information and have solved this. here is a link to the pastbin: http://pastebin.com/p8HjFdeu

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM