JSON.Net 示例失败
不知道为什么会失败,但这就是我所拥有的:
public class Message
{
public string Address { get; set; }
[JsonProperty(TypeNameHandling = TypeNameHandling.All)]
public object Body { get; set; }
}
public class SearchDetails
{
public string Query { get; set; }
public string Language { get; set; }
}
public void serialize()
{
Message message = new Message();
message.Address = "http://www.google.com";
message.Body = new SearchDetails
{
Query = "Json.NET",
Language = "en-us"
};
string json = JsonConvert.SerializeObject(message, Formatting.Indented);
}
我在 SerializeObject 上遇到异常: “找不到方法:‘Boolean System.Runtime.Serialization.DataContractAttribute.get_IsReference()’。”
它在 JsonObjectContract CreateObjectContract(Type objectType) on InitializeContract(contract); 上即将消亡。
我的声明有什么问题吗?
(提前致谢)
Not sure why this fails but here is what I have:
public class Message
{
public string Address { get; set; }
[JsonProperty(TypeNameHandling = TypeNameHandling.All)]
public object Body { get; set; }
}
public class SearchDetails
{
public string Query { get; set; }
public string Language { get; set; }
}
public void serialize()
{
Message message = new Message();
message.Address = "http://www.google.com";
message.Body = new SearchDetails
{
Query = "Json.NET",
Language = "en-us"
};
string json = JsonConvert.SerializeObject(message, Formatting.Indented);
}
I get an exception on the SerializeObject:
"Method not found: 'Boolean System.Runtime.Serialization.DataContractAttribute.get_IsReference()'."
It's dying in JsonObjectContract CreateObjectContract(Type objectType) on InitializeContract(contract);.
What is wrong with my decls?
(thanks in advance)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是否有帮助,但在将 Newtonsoft.Json 与 Windows Phone 7 应用程序一起使用时,我也遇到了类似的问题。
我使用 NuGet 安装,它添加的引用是 Newtonsoft.Json.Silverlight。
我删除了引用并添加了 Newtonsoft.Json.WindowsPhone,它解决了问题。
Not sure if this helps but I had a similar problem with Newtonsoft.Json when using it with a Windows Phone 7 application.
I had installed using NuGet and the reference it added was to Newtonsoft.Json.Silverlight.
I removed the reference and added Newtonsoft.Json.WindowsPhone instead and it resolved the problem.