我有一个示例代码片段,我正在其中加载json文档,但在解析级别遇到此失败:
类型提供者'ProviderImplementation.JsonProvider'在提供的类型'FSharp.Data.JsonProvider,Sample =“ ./ SampleModel.json”,成员'Parse'的上下文中报告错误。错误:在集合中找不到满足谓词的索引。
代码很简单,没有什么复杂的...
type Sample = JsonProvider<"./SampleModel.json">
let jsonFile = "./SampleModel.json"
let contentList = jsonFile |> File.ReadAllText |> Sample.Parse |> Array.toList
let rec printListContent (list: Sample.Root list) =
match list with
| [] -> "List is now empty."
| head :: _ -> sprintf "%s - %s" head.FirstName head.LastName
printListContent contentList
这是json文件:
[
{
"Id": 2,
"FirstName": "Bob",
"LastName": "Baggins",
"Hobbies": [
"Mountain Biking",
"Gaming",
"Music"
]
}
]
哦,我正在使用.NET 4.6和F#4.4.0.0和FSharp.Data v3.0.0