How do i pass a multidimensional array to my c# web api - javascript

I have a very large array that looks like this:
So in this case it consist of 85 arrays with 473 counts of data in each array.
I am currently passing this array to a web api to then process this data, this is how i do it:
function DeepDataProcess(array, callback) {
console.log(array[0]);
console.log(array);
var promise = HttpRequestFactory.Go({
url: 'api/ImportData/PostDataProcessing',
method: 'POST',
data: array[0] // this is the first index in the array I want to send the full array.
});
promise.then(function (response) { callback(response); }).catch(function (err) { console.log(err); });
}
as you can tell in my javascript i am only passing one array because when i try to send the full array my web api says my parameter is null. I also don't want to call my web api 85 times to get the full array in there, note: i know this array is a multidimensional array.
and below is my web api (c#):
[Route("PostDataProcessing")]//I have tried adding string[,] as the parameter
public IHttpActionResult PostDataProcessing(string[] array) //so that it can accept a multidimensional array but I still get a null value
{
var response = setDataProcessorService().DeepDataProcess(array);
return Ok(response);
}
when i send the full array my web api says my parameter array is empty.
How do I make my c# web api accept a multidimensional array as its parameter?
Below is the request I am making:

Related

vuejs make array of objects data

I have array of data (selected items) and I need to extract ids of this array into new array so I can send those ids only to back-end.
Code
method
toggleSelection(rows) {
console.log('this.multipleSelection : ',this.multipleSelection); // prints my default array (include all data)
this.multipleSelection.forEach(row => {
console.log('rows: ', row) // get each object of array (extract ids here)
// send axios request to backend (ids only)
});
},
Screenshot
here is result of console codes above
any idea?
At first I need to say I never worked with Vue.js. But in simple vanilla-javascript you could use the map function. I don't know if this works but Here is a possible answer:
yourids = this.multipleSelection.map(row => row.id);

How to query Firebase data after using .push() to add data?

Here is the code for when I'm pushing the data to Firebase:
firebase.database().ref(`booklogs/${uid}/${book_id}`).push(page_id)
booklogs :
{HUMjSHxVKAPfVXzOId9zCBkGOgv1:{
book28917: {
-KYp4FdYYODDZG1FX-Pb: 1
}
}
}
My problem is when I query the data, the child node of the ${book_id} includes the push key, but I only want to get the value which is 1 and not the push key.
The code I use to query is:
var booklogs = db.ref(`booklogs/${uid}/${project}`);
booklogs.once('value')
.then((snapshot) => {
console.log(`pages viewed are ${snapshot.key}: ${snapshot.val()}`);
console.dir(snapshot.val());
}).catch((error) => {
console.log(`Error : ${error}`);
});
The data returned in the console is:
pages viewed are 2634651: [object Object]
{ '-KYp4FdYYODDZG1FX-Pb': 1 }
Any input would be much appreciated. Thanks!
If you only want the '1' and not the push key, try using .set()
firebase.database().ref(`booklogs/${uid}/${book_id}`).set(page_id)
That will get rid of the object and just give you the value that you wanted. Push automatically generates a key for every value you add, so you will always get an object back. From the Firebase docs - "For basic write operations, you can use set() to save data to a specified reference, replacing any existing data at that path."
https://firebase.google.com/docs/database/web/read-and-write

extract specific part of API response to JSON object in Javascript

I am trying to interrogate an API response from the Recognize (fashion recognition) API. The data is returned as set out below. I am trying to extract the items of attire from the following object.
Object {data: " Array↵(↵ [id] => 1309↵)↵{"Status":true,"Data":{"VufindTags":["Dress"," Purse"]}}", status: 200, headers: function, config: Object, statusText: "OK"}config: Objectdata: " Array↵(↵ [id] => 1309↵)↵{"Status":true,"Data":{"VufindTags":["Dress"," Purse"]}}"headers: function (name) {status: 200statusText: "OK"__proto__: Object
I have tried to access using data.data which returned the following as a string:
" Array
(
[id] => 1309
)
{"Status":true,"Data":{"VufindTags":["Dress"," Purse"]}}"
I then tried to use JSON.parse to extract the data from the VufindTags. That did not work.
Is there a way to convert this into a JSON Object??
Thanks for any help!!
It looks like the vufind API is giving you PHP print_r output instead of JSON. The best thing to do would be to get them to fix their API. Failing that, you can pull the JSON-ified bits out. I had some success with this:
myObj = JSON.parse(apiOutput.slice(apiOutput.indexOf('{')))
...but I wouldn't put that into an app and call it production ready, especially when the API clearly isn't giving you what it should in the first place.

eagerloading expand() function in angularJS

I want the eagarloading expand function of breezejs to give me simple json objects when querying breeze's asp.net web api , so that i can iterate it in my angular views. like {{p.users.projects.projectname}} .. but results i get is not plain json when digging deep inside projects
function getUsersPartials() {
return EntityQuery.from('users').expand('projects')
.using(manager).execute()
.to$q(querySucceeded, _queryFailed);
function querySucceeded(data) {
users = data.results;
console.log(users);
log('Retrived [Users Partials] from remote data source ', users.length, true);
return users;
}
}
you can use .noTracking() on the query in order to get a simple json object

Is it possible to retrieve a record from parse.com without knowing the objectId

See the sample code below - in this case, the objectId for the record I am trying to retrieve is known.
My question is, if I don't know the Parse.com objectId, how would I implement the code below?
var Artwork = Parse.Object.extend("Artwork");
var query = new Parse.Query(Artwork);
query.get(objectId, {
success: function(artwork) {
// The object was retrieved successfully.
// do something with it
},
error: function(object, error) {
// The object was not retrieved successfully.
// warn the user
}
});
Query.get() is used when you already know the Parse object id.
Otherwise, one can use query.find() to get objects based on the query parameters.
Sure, you can use Parse Query to search for objects based on their properties.
The thing that wasn't clear to me in the documentation is that once you get the object in the query, you would need to do:
With Query (can return multiple objects):
artwork[0].get('someField');
With 'first' or 'get':
artwork.get('someField');
You cannot do something like artwork.someField like I assumed you would

Categories

Resources