【问题标题】:System.ArgumentException, when passing parameter using InvokeApiAsync ()System.ArgumentException,使用 InvokeApiAsync () 传递参数时
【发布时间】:2016-02-01 05:28:13
【问题描述】:

尝试将一些参数传递给我在 azure 移动服务上运行的自定义 API,使用列表引用和对象作为参数发送。然后我遇到了这个错误。

无法确定 App7.DataModels.FriendCircle 类型的 JSON 对象类型。

FriendCircle friendcircle = new FriendCircle();
List<Invitee> inviteelist;
try
{

    Object[] ob = new Object[2] { friendcircle, inviteelist };
    await App.azure_rendezvous_mobile_service_3Client.InvokeApiAsync("saveinvite", new JObject(new JProperty("params", ob)));

} 
catch (MobileServiceInvalidOperationException ex) 
{
    System.Diagnostics.Debug.WriteLine("Exception is :" + ex.Message);

}

【问题讨论】:

  • 您能否附上从中生成的 JSON 字符串以及您的云服务预期的数据结构
  • @AydinAdn 不明白你说什么
  • 当您调用 API 时,您在后台将您的类的 JSON 表示发送到 API,API 告诉您 JSON 对象与它可以确定的任何东西都不相似
  • @AydinAdn 不,它不会这样发生,我只想向自定义 api 发送一个 List 类型引用和一个对象,知道如何做到这一点吗?
  • 伙计,如果您忽略我告诉您的内容,我无法帮助您,我可以在您的代码中清楚地看到您将对象转换为 JSON 对象,并且您已经清楚地发布了错误正在抱怨 JSON 对象类型。

标签: c# azure argumentexception


【解决方案1】:

我尝试并能够向 azure custom api 发送请求。!! 将我的 List 引用和 Object 朋友圈序列化为 Json 并将其连接为 Json 属性。

var jsoninviteelist= JsonConvert.SerializeObject(inviteelist);
var jsonfriendcircle = JsonConvert.SerializeObject(friendcircle);
await App.azure_rendezvous_mobile_service_3Client.InvokeApiAsync("saveinvite",new JObject(new JProperty("jsoninviteelist",jsoninviteelist),new JProperty("jsonfriendcircle", jsonfriendcircle)));

P.S Install Package>> NuGet manager 中的 Newtonsoft.Json 并将其用作参考。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-09
    • 1970-01-01
    • 1970-01-01
    • 2012-08-13
    • 2012-05-24
    • 2011-04-22
    相关资源
    最近更新 更多