我需要获取 JSON
{
"question":"q1",
"answers": {
1:"ans1",
2:"ans2",
3:"ans3"
}
"corr":[1,2]
}
用这个表达式包含 LINQ
JObject jsonContent =
new JObject(
new JProperty("question", _question),
new JProperty("answers",
new JObject(
from ans in _answers
select new JProperty (ans.Key.ToString(),ans.Value))),
new JProperty("corr",
new JArray(
from ans in _correctAnswers
select ans)));
在哪里
string _question;
List<int> _correctAnswers;
Dictionary<int, string> _answers;
我在将 Dictionary 转换为 JProperty 时遇到问题
System.ArgumentNullException: Value cannot be null.
Parameter name: source
更新:所有值都已设置。没有空答案
UPD2:抱歉。一切正常。问题出在数据库访问层
最佳答案
看起来字典中可能有一个答案为空
尝试:
选择新的 JProperty (ans.Key.ToString(),ans.Value ?? string.Empty)
https://stackoverflow.com/questions/4655152/
相关文章:
visual-studio-2010 - TFS Team Build MSTest 运行持续时间太
java - 为什么当我在另一台计算机上加载我的工作区时 Eclipse 显示错误?
asp.net - "Invalid use of response filter"压缩来自 IHt
unicode - 无法使用自定义操作将 MSI 安装到用户名中包含非 ascii 字符的非管理员
r - 如何使用 RODBC 或 RCurl 从 R 中受密码保护的 Sharepoint 2007
.net - ToString() 和调试器的字符串可视化工具