namespace Booking.Areas.Golfy.Models
{
public class Time
{
public string time { get; set; }
public int holes { get; set; }
public int slots_available { get; set; }
public decimal? price { get; set; }
public int? Nextcourseid { get; set; }
public bool ShouldSerializeNextcourseid
{
get
{
return this.Nextcourseid != null;
}
}
public bool? allow_extra { get; set; }
public bool ShouldSerializeallow_extra
{
get
{
return this.allow_extra != null;
}
}
}
}
namespace Booking.Areas.Golfy.Controllers
{
public class TeetimesController : Controller
{
//
// GET: /Golfy/Teetimes/
public ActionResult Index(
string date,
int? courseid = null,
int? clubid = null,
int? holes = null,
int? available = null,
int? prices = null
)
{
var DateFrom = DateTime.ParseExact(date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
Teetimes r = BookingManager.GetBookings(new Code.Classes.Params.ParamGetBooking()
{
ClubID = clubid
, DateFrom = DateFrom
, DateTo = DateFrom.AddDays(1)
, GroundID = courseid
});
return Json(r, JsonRequestBehavior.AllowGet);
}
}
}
上面的web服務返回JSON字符串與時間的幾個intance。
我希望屬性Nextcourseid和allow_extra在值爲空時不會被輸出。
我試了ShouldSerializeXxx,但它似乎並沒有工作。
供參考:我也嘗試過[ScriptIgnore],但不是有條件的。
'JsonProperty'設置完美。謝謝。 – Kon