HappyTeaKid
❔ Get value out of deserialized json object.
I need to get value out of meta, from the "object".
As for now I also use this:
Dictionary<string, object> msg = (Dictionary<string, object>)result;
But since its generic Im not sure how to access the field value. Any help?
These dont work:
var result = data["meta"]["object"].Value<string>();
var result = data.SelectToken("meta.object").ToString();
var result = data.Descendants()
.OfType<JProperty>()
.FirstOrDefault(x => x.Name == "object")
?.Value;
And here is the json:
14 replies
✅ Pick random elements from array based on seed and randomise the order based also on seed.
I have an array with unique objects.
I'm writing this in fronted, Javascript and it looks should take these parameters:
let arrayWithObjects [new obj(x,y), new obj(a,b), new obj(d,e)... ] ;
function getRandomCards( seed, arrayWithObjects, newArrayLength){
//some code
return [x,y];
};
Seed is the parameter given by the user.
ArrayWithObjects is the array that I should take the objects out.
NewArrayLength should be the amount of object to pick.
TLDR:
Create a new array with a specified count by the user of unique objects from different array and then randomise the order(with seed parameter so that the outcome is repeatable), JavaScript.
15 replies
ConsoleApp Freeze user input for 1sec [Answered]
I need to freeze user input for 1 second after the last user input.
What i use for the input in a do while loop is this:
input = Console.ReadKey(true);
Then I call the method:
public void timeout(){
Stopwatch sw = new Stopwatch();
Random random = new Random();
var ranNum = random.Next(650, 950);
sw.Start(); while (true) { if (sw.Elapsed.TotalMilliseconds > ranNum) { break; } } sw.Stop(); } Problem is that it still reads user input while the timout is happening. System thread freeze also do not work. Please advice!
sw.Start(); while (true) { if (sw.Elapsed.TotalMilliseconds > ranNum) { break; } } sw.Stop(); } Problem is that it still reads user input while the timout is happening. System thread freeze also do not work. Please advice!
32 replies