AspNetCore.FSharpCompilerJson 1.0.4

Suggested Alternatives

AspNetCore.UnquotedJson

There is a newer version of this package available.
See the version list below for details.
dotnet add package AspNetCore.FSharpCompilerJson --version 1.0.4
NuGet\Install-Package AspNetCore.FSharpCompilerJson -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AspNetCore.FSharpCompilerJson" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspNetCore.FSharpCompilerJson --version 1.0.4
#r "nuget: AspNetCore.FSharpCompilerJson, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AspNetCore.FSharpCompilerJson as a Cake Addin
#addin nuget:?package=AspNetCore.FSharpCompilerJson&version=1.0.4

// Install AspNetCore.FSharpCompilerJson as a Cake Tool
#tool nuget:?package=AspNetCore.FSharpCompilerJson&version=1.0.4

本NuGet包提供把FSharpCompiler.Json的功能整合进入ASP.NET中,用于替换ASP.NET中内置的Json功能。

用法

新建一个ASP.NET Core Web 应用程序

安装NuGet包:

install-package Microsoft.AspNetCore.SpaServices.Extensions
install-package AspNetCore.FSharpCompilerJson

序列化控制器行为的结果为JSON

修改方法ConfigureServices,向其中添加依赖注入:

public void ConfigureServices(IServiceCollection services) {
    ...
    FSharpCompilerJsonDependencyInjection.AddFSharpJson(services);
}

这个配置意味着操作返回JsonResult类型时,ASP.NET会用FSharpCompiler.Json序列化类型。例如:

    [<HttpGet>]
    member this.action() = 
        ...
        JsonResult data

data将会使用FSharpCompiler.Json序列化为Json,并放到请求的响应中。

读取Request.Query的方法

在控制器的操作中:

    [<HttpGet>]
    member this.kvps() = 
        let kvps = this.Request.Query |> Query.toPairs
        ...

kvps的类型是seq<string*string>,比如请求中的查询字符串:

?foo=bar&baz=[~qux~,~quux~]

对应的kvps为

["foo","bar";"baz","[~qux~,~quux~]"]
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 581 11/29/2021
1.0.8 561 10/27/2021
1.0.7 591 10/25/2021
1.0.6 601 7/23/2021
1.0.5 540 7/19/2021
1.0.4 542 6/21/2021
1.0.3 656 4/14/2021
1.0.2 726 4/7/2021
1.0.1 741 4/1/2021
1.0.0 546 3/31/2021

update fsharpcompiler.json