2023年1月13日 星期五

使用 System.Text.Json出現 Cannot get the value of a token type 'String' as a number

 參考文章 :

System.Text.Json與 比較 Newtonsoft.Json ,並移轉至System.Text.Json

System.Text.Json: (De)serialization support for quoted numbers #30255

原本使用 Newtonsoft Json.Net 的程式是不會出現錯誤訊息,但是因為改用 System.Text.Json後執行 JsonSerializer.Deserialize 就出現這個錯誤,因為如果在 json string的數字如果是用雙引號的話就會出現,解決方式為如下