How to send array of object
See original GitHub issueHi, i have tried these two methods below but i still can’t get it done, it always send array of object as a string
instead of array of object. may i know is there any possible solution for this problem?
Method#1
var data = $scope.dealsData;
Upload.upload({
url: '/api/postDeals',
fields:data,
data:{favour:$scope.choices},
file: file
}
in my nodejs console
{ deals_name: 'ad',
deals_price: '12.12',
deals_amount: '12',
deals_description: 'asd',
deals_term_condition: 'asd',
favour_type: 'survey',
data: '{"favour":[{"type":"mcq","$$hashKey":"object:67","mcq_question":"asd","mcq_choice1":"asd","mcq_choice2":"asd"},{"type":"open_ended","$$hashKey":"object:68","open_ended_question":"asd"}]}' }
if i do it the usual way i don’t have the $$hashkey or object:6x thingy in my json Method#2
$scope.dealsData.favour = angular.toJson($scope.choices);
var data = $scope.dealsData;
Upload.upload({
url: '/api/postDeals',
fields:data,
file: file
}
in my nodejs console
{ deals_name: 'asd',
deals_price: '12.12',
deals_amount: '12',
deals_description: 'asd',
deals_term_condition: 'asd',
favour_type: 'survey',
favour: '[{"type":"mcq","mcq_question":"asd","mcq_choice1":"asd","mcq_choice2":"asd"},{"type":"open_ended","open_ended_question":"asd"}]' }
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Passing array of objects as parameter in C++ - GeeksforGeeks
Array of Objects :It is an array whose elements are of the class type. It can be declared as an array of any...
Read more >passing Object into Array - javascript - Stack Overflow
This is because, Object are passed by reference. You will have to create different object in every iteration. Following is the sample.
Read more >How to pass array of object as request parameter in jsp
Hi all, Can any one please tell me ho to pass array of object as request parameter in jsp and retrieve it in...
Read more >JSON Array Literals - W3Schools
Arrays in JSON are almost the same as arrays in JavaScript. In JSON, array values must be of type string, number, object, array,...
Read more >How to send array as parameter in API Call??
If I now want to add this array to a json object you would this: Set Variable[ $json ;. JsonSetElement( "{}" ; [...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just had the same issue. As per the docs using arrayKey: ‘[]’ solved the issue for me e.g.
Upload.upload({ data: val, arrayKey: '[]' })
Cases:
Case 1: when
fields
is object,then the code is send correct params:
{fields: {"name": "Kuldeep Aggarwal"}}
Case 2: when
fields
is array:then the code send incorrect params =>
{fields: {"0": { "name": "Kuldeep Aggarwal" }}}
instead it should send params =>
{fields: [{"name": "Kuldeep Aggarwal"}] }
So, if you think my assumption is right then I would like to contribute and create a PR for this issue.