开发者

Object Serialization to JSON, how to serialize Attributes (like XML)

I am a Newbie to Json, I just started using Json.NET from today.

I was looking for a way to convert XML to JSON and landed in Json.NET.

I have a class that I serialize to XML and then convert to JSON, but this is hampering performance. So I started using [JsonProperty] attributes inside my class to convert to JSON.

I have few attributes which are a part of XML Element, But How to I serialize XML Attributes from my objects to JSON? We have [XMLAttribute] for this in XML, is ther开发者_如何学JAVAe anything equivalent in JSON.NET?

sample object:

Thanks in advance

-ash5


XML distinguishes between attributes and elements, in JSON, you only have attributes. When you serialize XML data using Json.Net, child elements are serialized as attributes, and you can access them using syntax parent.childElementName, but XML attributes will have to be accessed using the syntax parent[@attributename]. And remember, everything is case sensitive in JSON.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜