Fable/Thoth compile error: toJson is not defined
Fable/Thoth compile error: toJson is not defined
我正在尝试使用 Fable 执行 POST 请求,遵循本教程:https://fable.io/fable-powerpack/posts/fetch.html
我遇到这个编译错误:
error FSHARP: The value or constructor 'toJson' is not defined. Maybe you want one of the following:
JSON (code 39)
@ ./UI/UI.fsproj 1:0-24 1:0-24
这是我的代码:
let submitForm =
let txtName = getInputElementById("txtName")
let postData = { Name = txtName.value }
let requestProps =
[ RequestProperties.Method HttpMethod.POST
; requestHeaders [ContentType "application/json"]
; RequestProperties.Body (unbox (toJson postData))
]
//Encode.Auto.toString(1, postData)
//toJson
//Fable.Core.JS.JSON.stringify
promise {
let! response = fetch "http://localhost:5000/employee/create" requestProps
let responseText = response.text()
Browser.console.log responseText
} |> ignore
我在 Fable/.fable/Thoth.Json.2.0.0/Encode.fs:
中也遇到了这些编译错误
The value, constructor, namespace or type 'Array' is not defined. (code 39)
The value, constructor, namespace or type 'JSON' is not defined.
我猜这是因为寓言引用的是 Thoth 2.0.0,而不是最新版本。我该如何解决这个错误?
https://github.com/jaydpather/FunctionalCrudForms/blob/master/Fable/UI/UI.fs
免责声明我是 Thoth.Json.
的维护者
您似乎使用的是 2 年以上的寓言版本。
fable-powerpack 已被弃用并被拆分成不同的包。但是我们好像忘了更新这个网站。
对于 Fetch API,它现在位于包 Fable.Fetch 内。
toJson
不存在了建议使用Thoth.Json or Fable.SimpleJson
还有包 Thoth.Fetch 已经将 Fetch 和 Thoth.Json 粘合在一起,因此您不必编写(反)序列化部分。
在你的情况下,它会给出类似的东西:
let createBook () : JS.Promise<unit> =
promise {
let url = "http://localhost:5000/employee/create"
let txtName = getInputElementById("txtName")
let data =
{| Name = = txtName .Value |} // Using an anonymous for simplicity
return! Fetch.post(url, data, caseStrategy = CamelCase)
}
我正在尝试使用 Fable 执行 POST 请求,遵循本教程:https://fable.io/fable-powerpack/posts/fetch.html
我遇到这个编译错误:
error FSHARP: The value or constructor 'toJson' is not defined. Maybe you want one of the following:
JSON (code 39)
@ ./UI/UI.fsproj 1:0-24 1:0-24
这是我的代码:
let submitForm =
let txtName = getInputElementById("txtName")
let postData = { Name = txtName.value }
let requestProps =
[ RequestProperties.Method HttpMethod.POST
; requestHeaders [ContentType "application/json"]
; RequestProperties.Body (unbox (toJson postData))
]
//Encode.Auto.toString(1, postData)
//toJson
//Fable.Core.JS.JSON.stringify
promise {
let! response = fetch "http://localhost:5000/employee/create" requestProps
let responseText = response.text()
Browser.console.log responseText
} |> ignore
我在 Fable/.fable/Thoth.Json.2.0.0/Encode.fs:
中也遇到了这些编译错误The value, constructor, namespace or type 'Array' is not defined. (code 39)
The value, constructor, namespace or type 'JSON' is not defined.
我猜这是因为寓言引用的是 Thoth 2.0.0,而不是最新版本。我该如何解决这个错误?
https://github.com/jaydpather/FunctionalCrudForms/blob/master/Fable/UI/UI.fs
免责声明我是 Thoth.Json.
的维护者您似乎使用的是 2 年以上的寓言版本。
fable-powerpack 已被弃用并被拆分成不同的包。但是我们好像忘了更新这个网站。
对于 Fetch API,它现在位于包 Fable.Fetch 内。
toJson
不存在了建议使用Thoth.Json or Fable.SimpleJson
还有包 Thoth.Fetch 已经将 Fetch 和 Thoth.Json 粘合在一起,因此您不必编写(反)序列化部分。
在你的情况下,它会给出类似的东西:
let createBook () : JS.Promise<unit> =
promise {
let url = "http://localhost:5000/employee/create"
let txtName = getInputElementById("txtName")
let data =
{| Name = = txtName .Value |} // Using an anonymous for simplicity
return! Fetch.post(url, data, caseStrategy = CamelCase)
}