我有以下实体类:
public class FacebookComment : BaseEntity
{
[BsonId(IdGenerator = typeof(ObjectIdGenerator))]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
[JsonProperty("_id")]
public ObjectId Id { get; set; }
public int? OriginalId { get; set; }
public DateTime Date { get; set; }
public string Message { get; set; }
public string Sentiment { get; set; }
public string Author { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当此对象序列化为JSON时,我希望Id字段写为"_id":{...}.AFAIK,我只需要将所需的属性名传递给JsonProperty属性; 我应该好好去.但是,当我调用JsonConvert.SerializeObject; 它似乎忽略了我的属性并改为呈现:
{
Author: "Author name",
Date: "/Date(1321419600000-0500)/",
DateCreated: "/Date(1323294923176-0500)/",
Id: {
CreationTime: "/Date(0)/",
Increment: 0,
Machine: 0,
Pid: 0,
Timestamp: 0
},
Message: …Run Code Online (Sandbox Code Playgroud)