简体   繁体   English

从 Appery 项目发送数组到 REST API

[英]Sending array to REST API from Appery project

I have an external rest api that expects to get an array of json objects.我有一个外部 rest api 期望得到一个 json 对象的数组。 How can I rest in javascript?我怎样才能在javascript中输入rest? I tried like this but got an error message:我这样试过,但收到一条错误消息:

send_ivrs.execute({
data: [{
"company": "test",
"phone": "0123456789"
}]
});

The error I got (400 - bad request):我得到的错误(400 - 错误的请求):

Cannot deserialize the current JSON object (eg {"name":"test"}) into type 'System.Collections.Generic.List' because the type requires a JSON array (eg [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (eg [1,2,3]) or change the deserialized type so that it is a normal .NET type (eg not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\r\nPath '0', line 1, position 5.无法将当前 JSON object(例如 {"name":"test"})反序列化为类型“System.Collections.Generic.List”,因为该类型需要 JSON 数组(例如 [1,2,3])才能正确反序列化。 \r\n要修复此错误,请将 JSON 更改为 JSON 数组(例如 [1,2,3])或更改反序列化类型,使其成为正常的 .NET 类型(例如不是像 integer 这样的原始类型,不是集合类型如数组或列表),可以从 JSON object 反序列化。也可以将 JsonObjectAttribute 添加到类型以强制它从 JSON object 反序列化。\r\n路径“0”,第 1 行,8811773847.317

This is a general requirement for API calls.这是 API 呼叫的一般要求。 API Express, and Server Code support object body request, not an array. API Express,Server Code 支持object body 请求,不是数组。 Please send the object with the property = array, instead of the array directly.请发送属性为数组的object,不要直接发送数组。 I mean the request should be like:我的意思是请求应该是这样的:

send_ivrs.execute({
   data: {"myArray": [{
      "company": "test",
      "phone": "0123456789"
   }]}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM