我想使用 Fable.JsonConverter。
我的测试代码(几乎复制这个)FableJson.fs如下,
module FableJson
open Newtonsoft.Json
// Always use the same instance of the converter
// as it will create a cache to improve performance
let private jsonConverter = Fable.JsonConverter() :> JsonConverter
// Serialization
let toJson value =
JsonConvert.SerializeObject(value, [|jsonConverter|])
// Deserialization
let ofJson<'T> json =
JsonConvert.DeserializeObject<'T>(json, [|jsonConverter|])
Run Code Online (Sandbox Code Playgroud)
并paket.dependencies添加 nuget Fable.JsonConverter 文件
source https://nuget.org/api/v2
storage:none
clitool dotnet-fable
nuget Fable.Core
nuget Fable.Import.Browser
nuget Fable.JsonConverter
Run Code Online (Sandbox Code Playgroud)
并src/paket.references添加文件 Fable.JsonConverter
dotnet-fable
Fable.Core
Fable.Import.Browser
Fable.JsonConverter
Run Code Online (Sandbox Code Playgroud)
但无法编译。
~~~ snip ~~~
ERROR in ./src/FableJson.fs
d:/SRC/Repos/Fable/testJsonConverter/src/FableJson.fs(11,4): (11,57) error FABLE: Cannot find replacement for Newtonsoft.Json.JsonConvert::SerializeObject
@ ./src/App.fs 6:0-48
@ ./src/testJsonConverter.fsproj
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/testJsonConverter.fsproj
ERROR in ./src/FableJson.fs
d:/SRC/Repos/Fable/testJsonConverter/src/FableJson.fs(15,4): (15,62) error FABLE: Cannot find replacement for Newtonsoft.Json.JsonConvert::DeserializeObject
@ ./src/App.fs 6:0-48
@ ./src/testJsonConverter.fsproj
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/testJsonConverter.fsproj
ERROR in ./src/FableJson.fs
d:/SRC/Repos/Fable/testJsonConverter/src/FableJson.fs(7,28): (7,49) error FABLE: Cannot find replacement for Fable.JsonConverter::.ctor
@ ./src/App.fs 6:0-48
@ ./src/testJsonConverter.fsproj
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/testJsonConverter.fsproj
Run Code Online (Sandbox Code Playgroud)
我应该怎么办?
@Maslow 是对的,在《神鬼寓言 2》中,我们删除了 Fable.JsonConverter,转而使用社区创建的库。
Thoth.Json 与 Thoth.Json.Net 相辅相成,允许您在后端使用相同的 API。
我认为 Fable.SimpleJson 也提供对后端的支持,但我不确定。
您可以使用 JavaScript 本机 API Fable.Core.JS.JSON.stringify,Fable.Core.JS.JSON.parse(x)但必须使用unbox/cast 来强制使用不安全且容易损坏的数据类型。
| 归档时间: |
|
| 查看次数: |
797 次 |
| 最近记录: |