一尘不染

将F#记录类型序列化为JSON,每个属性后均包含“ @”字符

json

DataContractJsonSerializer为F#记录类型创建JSON,该JSON类型在每个属性名称后均包含“
@”字符。有谁知道是否有可能获得不带符号结尾的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

阅读 244

收藏
2020-07-27

共1个答案