Announcement

Collapse
No announcement yet.

Conditional summation - Querying JSON with SelectToken

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • bro
    started a topic Conditional summation - Querying JSON with SelectToken

    Conditional summation - Querying JSON with SelectToken

    Hello

    My json data in a text-file:
    "age":"2019-01-20T19:17:12.58353" // UTC time
    "breads_eaten": 123
    I want to sum up the values "breads_eaten" under a certain condition: (DateTime)n["age"] < utc_time_now

    This code works:

    JObject o = JObject.Parse(File.ReadAllText(path));
    decimal sum = o["table.entry"].Sum(m => (decimal)m.SelectToken("breads_eaten")); // OK
    Problem:
    I want to add a condition for the summation:
    decimal sum = o["table.entry"].Sum(m => (decimal)m.SelectToken("breads_eaten").Where(n => (DateTime)n["age"] < utc_time_now)); // ERROR
    That doesn't work! I get the error code CS0030(Microsoft Visual Studio).

    Who can help me to solve the problem?
    Last edited by geoffrey.mcgill; 2019-02-22 @ 04:33 PM.

  • bro
    replied
    My problem is solved. The where-function must be called first, then followed by the sum-function.

    Leave a comment:


  • geoffrey.mcgill
    replied
    ok, no problem bro.

    Leave a comment:


  • bro
    replied
    Hello,
    sorry, cannot, that's too much data.

    Leave a comment:


  • geoffrey.mcgill
    replied
    Hi. Please share a simplified Deck.NET link demonstrating as much of the scenario as you can.
    Last edited by geoffrey.mcgill; 2019-02-23 @ 12:27 AM.

    Leave a comment:

Working...
X