Skip to content

Unable to load document from JSON. #1849

@jalvespinto

Description

@jalvespinto

Is there an existing issue for this?

The question

I have create this simple text to see how jsonEncode(_controller.document.toDelta().toJson()). This was the text in markdown:

TITLE

CATEGORY: Category

LIST

  • Item
  • Item: item

ORDERED LIST

  1. First
  2. Second: second

This is what jsonEncode(_controller.document.toDelta().toJson()) returned:

[{"insert":"Title\n","attributes":{"header":3}},{"insert":"CATEGORY: ","attributes":{"bold":true}},{"insert":"Category\n\n"},{"insert":"LIST","attributes":{"bold":true}},{"insert":"\n"},{"insert":"Item\n","attributes":{"list":"bullet"}},{"insert":"Item:","attributes":{"list":"bullet","bold":true}},{"insert":" item\n","attributes":{"list":"bullet"}},{"insert":"\n"},{"insert":"ORDERED LIST","attributes":{"bold":true}},{"insert":"\n"},{"insert":"First\n","attributes":{"list":"ordered"}},{"insert":"Second: ","attributes":{"list":"ordered","bold":true}},{"insert":"second\n","attributes":{"list":"ordered"}}]

Now, when I try to get a Document from it (using Document.fromJson(jsonDecode(jsonEncode(_controller.document.toDelta().toJson()))) it doesn't work because it has \n instead of \\n and because there is no {"insert": "\\n"} at the end (or I need to append 'r' in front of the string to denoted as a raw string. How should I deal with this? tks

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions