Search code examples
jsondartextract

How to grab the second occurrence between quotation marks?


I want to grab the datetime from the following:

{
    "due": "2024-04-27 17:50:02.852Z",
    "stability": 0,
    "difficulty": 0,
    "elapsedDays": 0,
    "scheduledDays": 0,
    "reps": 0,
    "lapses": 0,
    "state": "State.newState",
    "lastReview": "2024-04-27 17:50:02.852Z"
}

I want the "2024-04-27 17:50:02.852Z" without the quotation marks.

I have found this: RegEx: Grabbing values between quotation marks

But that grabs all the occurrences..

Edit: I'm trying to achieve this in the Dart language btw...


Solution

  • You probably want to use JSON.parse(string)["due"] to achieve this. This is because the order of the fields might change in future, and also, it's more intuitive to access the field by name.

    However, if you really want to process it as a string, you can get the second value with string.split('"')[3]