我花了一整天的时间试图找到答案,但我遇到的一切都不适合我。我正在使用azure移动服务,我正在尝试更新数据库中已有的数据。这里的文档https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-how-to-use-client-library/给了我以下代码,让我修改条目
JObject jo = new JObject();
jo.Add("Id", "37BBF396-11F0-4B39-85C8-B319C729AF6D");
jo.Add("Text", "Hello World");
jo.Add("Complete", false);
var inserted = await table.UpdateAsync(jo);
我已将此代码实现为(我有一行ID为1234的数据)
public async void updatedata()
{
CurrentPlatform.Init();
JObject jo = new JObject();
jo.Add("Id", "1234");
jo.Add("Text", "Hello World");
var inserted = await client.GetTable<Item>().UpdateAsync(jo);
}
让我的表定义如此
public class Item
{
[JsonProperty(PropertyName = "Id")]
public string Id { get; set; }
[JsonProperty(PropertyName = "Text")]
public string Text { get; set; }
然后设置获取移动服务的信息 MobileServiceClient客户端; IMobileServiceTable todoTable;
public void setNumbers()
{
CurrentPlatform.Init();
client = new MobileServiceClient(
"AppUrl",
"AppKey"
);
todoTable = client.GetTable<Item>();
}
在所有这些之后我得到了警告
var inserted = await client.GetTable<Item>().UpdateAsync(jo);
读取&#34;严重性代码描述项目文件行 警告CS1701假设程序集引用&quot; Newtonsoft.Json,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed&#39;由Microsoft.WindowsAzure.Mobile&#39;使用。匹配身份&#39; Newtonsoft.Json,Version = 7.0.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed&#39; &#39; Newtonsoft.Json&#39;,您可能需要提供运行时策略&#34;
当我运行它时,它会抛出一个Unhandled Exception说
"System.ArgumentException: The casing of the 'id' property is invalid.
Parameter name: instance
我该如何解决这个问题?为什么会这样?我假设我错过了一些非常简单的东西,但没有找到它的运气。非常感谢任何帮助!
答案 0 :(得分:0)
Make all your Property Names in [JsonProperty(PropertyName = "lower case")]
lower case.
Here:
public class Item
{
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
[JsonProperty(PropertyName = "text")]
public string Text { get; set; }
}