如何在JSON序列化期间删除$ id [英] how to remove $id during JSON serialization
本文介绍了如何在JSON序列化期间删除$ id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用NewtonSoft.JSON.跑步时
I am using NewtonSoft.JSON. When running
JsonConvert.SerializeObject(myObject)
它向我的JSON添加$id
值-像这样:
it is adding an $id
value to my JSON - like this:
"$id": "1",
"BookingId": 0,
"CompanyId": 0,
"IsCashBooking": false,
"PaymentMethod": 0,
"IsReferral": false,
"IsReferralPercent": false,
"ReferralPaymentType": 0,
"ReferralDues": 0,
"PassengerId": 0,
"DepartmentID": 0,
"CostCenterID": 0,
"DeadMiles": 0
我们可以使用某些JsonSerializerSettings或任何其他方法删除此$id
吗?
Can we remove this $id
with some JsonSerializerSettings or by any other method?
如果是-那么如何...
If yes - then how...
推荐答案
我将此代码添加到WebApiConfig注册方法中,并且摆脱了JSON中的所有$ id.
I added this code to my WebApiConfig register method and I got rid of all $id in JSON.
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
这篇关于如何在JSON序列化期间删除$ id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文