DataContractJsonSerializer 为在每个属性名称后包含“@”字符的 F# 记录类型创建 JSON。有谁知道是否可以获得没有此尾随 at 符号的 JSON?
{"heart_rate@":20,"latitude@":45.0,"longitude@":108.0,"name@":"Rambo"}
这是我用来输出这个样本的脚本
#r "System.Xml"
#r "System.Runtime.Serialization"
open System.Text
open System.Runtime.Serialization.Json
open System.IO
type Update = {
name: string;
latitude: decimal;
longitude: decimal;
heart_rate: int}
let update = {name = "Rambo"; latitude = 45.0m; longitude = 108.0m; heart_rate = 20}
let serializer = new DataContractJsonSerializer( typeof<Update> )
let stream = new MemoryStream()
let data = serializer.WriteObject(stream, update)
let updateData = stream.ToArray()
let json = (Encoding.UTF8.GetString(updateData))
printfn "%s" json