Announcement

Collapse
No announcement yet.

Conditional summation - Querying JSON with SelectToken

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

    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.

    #2
    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.

    Comment


      #3
      Hello,
      sorry, cannot, that's too much data.

      Comment


        #4
        ok, no problem bro.

        Comment


          #5
          My problem is solved. The where-function must be called first, then followed by the sum-function.

          Comment

          Working...
          X