0

I fetch Json from api.

"fields": {
        "document": "some text: \n\n__textToRemove:__\ textToRemove \n\n__some text:__\ some text"
        }

How I can remove part of string? I want to cut "textToRemove"

3
  • 1
    Does this - (link) - answer your quesiton? Commented May 27, 2021 at 10:06
  • 4
    In most cases it is the best to fully deserialize JSON with any library, modify the data then serialize back. It may sound like a quite a lot of work (for CPU, not for a developer) for such a simple task, it is definitely less efficient than modifying the string directly, but this is much more reliable and safer approach. If you don't need a very high efficiency, it is probably better. Commented May 27, 2021 at 10:11
  • 1
    And for serialization library I would suggest kotlinx.serialization - it is very efficient and it is de facto standard in Kotlin. If you prefer something more Java-ish, then Jackson is probably the most popular. Commented May 27, 2021 at 10:15

1 Answer 1

0

You have to remove back slash or something else with the help of this type of code.

  val dummyText  = "Lorem Ipsum is\\ simply\\ dummy\\text of the\\ printing and 
  typesetting industry. Lorem Ipsum has been the\\ industry's";

  val fields = dummyText.replaceAll("\\", ""); or dummyText.replace("\\","")

and then convert into JsonObject. I hope it will be helpful to you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.