我是編程新手,F#是我的第一語言。F#:保存JSON數據
這裏是我的代碼的相關部分:
let internal saveJsonToFile<'t> (someObject:'t) (filePath: string) =
use fileStream = new FileStream(filePath, FileMode.OpenOrCreate)
(new DataContractJsonSerializer(typeof<'t>)).WriteObject(fileStream, someObject)
let testList = new List<Fighter>()
saveJsonToFile testList<Fighter> @"G:\User\Fighters.json"
我以前創建的類型戰鬥機的F#記錄。
當我嘗試運行「saveJsonToFile testList @」G:\ User \ Fighters.json「」,「testList」被強調爲紅色並顯示錯誤消息:「Unexpected type arguments」。
出了什麼問題?我錯過了什麼?
而是'新System.Collections.Generic.List <'a>()',你可以使用'新ResizeArray <'a>的()'。另外,'[]'不是構造函數;這是一個價值。試試這個:'System.Object.ReferenceEquals([],[])' – phoog 2015-04-02 18:13:14
@phoog http://tryfs.net/snippets/snippet-qm – 2015-04-02 19:12:13
我不明白你的觀點。當然,如果它們的類型不同,它們的情況就不一樣了。 – phoog 2015-04-02 20:38:41