开发者

JSON.Net serialization and custom objects

So I was working toward a fairly lightweight approach at serializing some of my objects, and was hoping to use NewtonSoft's JSON.Net.

The challenge is that I'm trying to use a simple interface for serializing an IDictionary. T in this case will be one of several entities in my domain开发者_运维知识库 that all have a Guid id (which becomes its key in the dictionary).

the problem I'm having is that JSON.Net is successfully serializing the dictionary key values and the Id property of the stored objects, but none of hte other properties (which, at this point, are all simple types). My serialization code is pretty much right off the jSON.Net website:

string json = JsonConvert.SerializeObject(data,Formatting.Indented);

"data" as I said is an IDictionary, and T is (for this test) an "Asset" type which right now just has a Guid ID and a String Name property. The output looks like this:

{
  "d1cb1764-66cd-4cfb-8f51-c0b8457ce00e": {
    "Id": "d1cb1764-66cd-4cfb-8f51-c0b8457ce00e"
  }
}

Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜