简体   繁体   中英

Json.net Serializer settings

I've below data in a DataTable and want to serialize it in JSON format.

在此处输入图片说明

What I'm getting is:

在此处输入图片说明

I want the data in "Roles" field to be separated by semi-colon (;).

What I want is:

在此处输入图片说明

I want each role in Roles field delimited by semi-colon to be an individual property. Went through the documentation but couldn't find any solution or setting for doing that: http://james.newtonking.com/json/help/index.html

Is it possible to achieve this purpose using Json.Net. Thanks for any help!

To do this, you will need to make your own inheritor of JsonWriter. Start with the source code for the JsonTextWriter found here:

https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/JsonTextWriter.cs

You will notice in that file the presence of WriteStartArray . It would be nice if you could just inherit from JsonTextWriter and modify the start/stop array methods. However, I don't see how you would call that internal method to go into Array mode. Also, you can override the WriteValueDelimiter method to insert semicolons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM