FSharpCompiler.Json
1.1.2
The new package implements all the features of this package and has a better API.
See the version list below for details.
dotnet add package FSharpCompiler.Json --version 1.1.2
NuGet\Install-Package FSharpCompiler.Json -Version 1.1.2
<PackageReference Include="FSharpCompiler.Json" Version="1.1.2" />
paket add FSharpCompiler.Json --version 1.1.2
#r "nuget: FSharpCompiler.Json, 1.1.2"
// Install FSharpCompiler.Json as a Cake Addin #addin nuget:?package=FSharpCompiler.Json&version=1.1.2 // Install FSharpCompiler.Json as a Cake Tool #tool nuget:?package=FSharpCompiler.Json&version=1.1.2
FSharpCompiler.Json
FSharpCompiler.Json
is a easy to use and configurable JSON framework for F#.
Flexible JSON serializer for converting between F# and JSON.
DU
Json
type for manually reading and writing JSON.High performance, faster than .NET's built-in JSON serializers.
功能
JsonString
序列化将某类型的对象为JSON字符串。
JsonString.serialize:'t -> string
例如:
let r = {| x = 0; y = false; |}
let y = JsonString.serialize r
should.equal y """{"x":0,"y":false}"""
反序列化将JSON字符串为某类型的对象。
JsonString.deserialize: string -> 't
例如:
let json = """{"x":0,"y":false}"""
let y = JsonString.deserialize<{|x:int;y:bool|}> json
let obj = {| x = 0; y = false; |}
should.equal y obj
动态序列化将某类型的对象为JSON字符串。
JsonString.serializeDynamic: Type -> obj -> string
例如:
let obj = {| x = 0; y = false; |}
let y = JsonString.serializeDynamic typeof<{|x:int;y:bool|}> obj
should.equal y """{"x":0,"y":false}"""
动态反序列化将JSON字符串为某类型的对象。
JsonString.deserializeDynamic: Type -> string -> obj
例如:
let json = """{"x":0,"y":false}"""
let y = JsonString.deserializeDynamic typeof<{|x:int;y:bool|}> json
let obj = box {| x = 0; y = false; |}
should.equal y obj
UrlQuery
是Url的Query部分字符串,解析为F#数据。
解析查询字符串中的单个键值对的字段值为F#类型的对象。
UrlQuery.parseField: string -> 't
例如:
let x = "[~xyz~,~123~]"
let y = UrlQuery.parseField<string[]> x
let z = [|"xyz";"123"|]
should.equal y z
解析整个查询字符串的键值对为F#类型的对象。
UrlQuery.parse: seq<string*string> -> 't
例如:
let pairs = ["foo","bar";"abc","[~xyz~,~123~]"]
let y = UrlQuery.parse<{|foo:string;abc:string[]|}> pairs
let z = {|abc=[|"xyz";"123"|];foo="bar"|}
should.equal y z
动态解析查询字符串的单个键值对的字段值为F#类型的对象。需要提供目标类型数据。
UrlQuery.parseFieldDynamic: Type -> string -> obj
例如:
let urljson = "[~xyz~,~123~]"
let y = UrlQuery.parseFieldDynamic typeof<string[]> urljson
let z = box [|"xyz";"123"|]
should.equal y z
动态解析整个查询字符串的单个键值对的字段值为F#类型的对象。需要提供目标类型数据。
UrlQuery.parseQueryDynamic: Type -> seq<string*string> -> obj
例如:
let pairs = ["foo","bar";"abc","[~xyz~,~123~]"]
let y = UrlQuery.parseQueryDynamic typeof<{|foo:string;abc:string[]|}> pairs
let z = box {|abc=[|"xyz";"123"|];foo="bar"|}
should.equal y z
JsonTree
所有格式的序列化都可以解析成Json
可区分联合,为了与JSON字符串格式区别,称其为树。
F#类型的对象转换为Json可区分联合类型。
JsonTree.read: 't -> Json
例如:
let x = {|foo="bar";abc = ["xyz";"123"]|}
let y = JsonTree.read<{|foo:string;abc:string list|}> x
should.equal y
<| Json.Object ["abc",Json.Array [Json.String "xyz";Json.String "123"];"foo",Json.String "bar"]
Json可区分联合类型转换为F#类型的对象。
JsonTree.write: Json -> 't
例如:
let json = Json.Object ["abc",Json.Array [Json.String "xyz";Json.String "123"];"foo",Json.String "bar"]
let y = JsonTree.write<{|foo:string;abc:string list|}> json
let z = {|foo="bar";abc = ["xyz";"123"]|}
should.equal y z
Json可区分联合类型序列化为JSON字符串。
JsonTree.stringifyJson: Json -> string
例如:
let json = Json.Object ["abc",Json.Array [Json.String "xyz";Json.String "123"];"foo",Json.String "bar"]
let y = JsonTree.stringifyJson json
let z = """{"abc":["xyz","123"],"foo":"bar"}"""
should.equal y z
Json字符串解析为JSON可区分联合类型。
JsonTree.parseJson: string -> Json
例如:
let x = """{"abc":["xyz","123"],"foo":"bar"}"""
let y = JsonTree.parseJson x
let json = Json.Object ["abc",Json.Array [Json.String "xyz";Json.String "123"];"foo",Json.String "bar"]
should.equal y json
Json可区分联合类型序列化为Urljson字符串。
JsonTree.stringifyUrljson: Json -> string
例如:
let json = Json.Object ["abc",Json.Array [Json.String "xyz";Json.String "123"];"foo",Json.String "bar"]
let y = JsonTree.stringifyUrljson json
let z = "{abc:[~xyz~,~123~],foo:~bar~}"
should.equal y z
Urljson格式的字符串解析为JSON可区分联合类型。
JsonTree.parseUrljson: string -> Json
例如:
let x = "{abc:[~xyz~,~123~],foo:~bar~}"
let y = JsonTree.parseUrljson x
let json = Json.Object ["abc",Json.Array [Json.String "xyz";Json.String "123"];"foo",Json.String "bar"]
should.equal y json
ASP.NET
为了将FSharpCompiler.Json
整合进入ASP.NET用于JSON的解析和序列化,使用库AspNetCore.FSharpCompilerJson
。
see also
可以应用于Asp.net项目序列化JSON格式,演练教程如下:https://github.com/xp44mm/UrljsonExample
项目内有其他文档。
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- FSharp.Core (>= 5.0.1)
- FSharp.Idioms (>= 1.1.8)
- FSharp.Literals (>= 2.2.1)
- FSharpCompiler.Analyzing (>= 1.0.3)
- FSharpCompiler.Parsing (>= 1.0.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on FSharpCompiler.Json:
Package | Downloads |
---|---|
AspNetCore.FSharpCompilerJson
AspNetCore extensions to use FSharpCompiler.Json for serialization/deserialization. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.2.0 | 662 | 11/29/2021 | |
1.1.7 | 628 | 10/27/2021 | |
1.1.6 | 682 | 10/25/2021 | |
1.1.5 | 399 | 8/22/2021 | |
1.1.4 | 705 | 7/23/2021 | |
1.1.3 | 658 | 7/19/2021 | |
1.1.2 | 641 | 6/21/2021 | |
1.1.1 | 745 | 4/10/2021 | |
1.1.0 | 751 | 4/7/2021 | |
1.0.8 | 796 | 4/1/2021 | |
1.0.7 | 502 | 4/1/2021 | |
1.0.6 | 609 | 3/29/2021 | |
1.0.5 | 452 | 3/29/2021 | |
1.0.4 | 466 | 3/12/2021 | |
1.0.3 | 508 | 2/28/2021 | |
1.0.2 | 482 | 2/28/2021 | |
1.0.1 | 437 | 2/16/2021 | |
1.0.0 | 452 | 2/12/2021 |
api