question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to send array of object

See original GitHub issue

Hi, 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:closed
  • Created 8 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
psnfrenchcommented, Mar 26, 2017

Just had the same issue. As per the docs using arrayKey: ‘[]’ solved the issue for me e.g. Upload.upload({ data: val, arrayKey: '[]' })

1reaction
kuldeepaggarwalcommented, Dec 10, 2015

Cases:

Case 1: when fields is object,

var val = { "name": 'kuldeep Aggarwal' }
Upload.upload({
  fields: val
})

then the code is send correct params: {fields: {"name": "Kuldeep Aggarwal"}}

Case 2: when fields is array:

var val = [{"name": "kuldeep Aggarwal"}]
Upload.upload({
  fields: val
})

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found