简体   繁体   中英

Sending array to REST API from Appery project

I have an external rest api that expects to get an array of json objects. How can I rest in javascript? I tried like this but got an error message:

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

The error I got (400 - bad request):

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.

This is a general requirement for API calls. API Express, and Server Code support object body request, not an array. Please send the object with the property = array, instead of the array directly. I mean the request should be like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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