c# - 将 Json.Net JValue 转换为 int

标签 c# json.net

我试过:

JValue myJValue = getJValue(someVar);
int storedValue = JsonConvert.DeserializeObject(myJValue);

但这似乎只对 JObjects 有效。有没有办法从 JValue 中获取整数?

最佳答案

也许这对你有帮助:

int storedValue = myJValue.ToObject<int>(); 

关于c# - 将 Json.Net JValue 转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30393079/

相关文章:

c# - 另存为 8 位 PNG

c# - 如何将 C# 8.0 可空引用类型与 Entity Framework Core 模型一起使用?

c# - 将 json 字符串转换为对象

c# - 如何解决CA2202 :To avoid generating a System. ObjectDisposeException警告

c# - GoCardless 事件不会反序列化

c# - 这是使用模拟对存储库进行单元测试的正确方法吗?

c# - 'Microsoft.ACE.OLEDB.12.0' 提供者未在 64 位机的本地机器上注册

c# - LINQ to SQL Where 子句可选条件

asp.net-mvc-4 - MVC4 JSON.Net oob

linq - 将 LINQ 对象序列化为 JSON 字符串 - 巨大的字符串