T
T
TikTak12362019-09-02 13:02:13
Java
TikTak1236, 2019-09-02 13:02:13

How can I replace the curly braces with a real value inside a JSON string?

I am developing an Android project. In development I use Retrofit, Gson, RxJava.
For example, I can get such a response from the server and I have to replace curly braces with real values.
{
"text": "Hello {0} World {1} This is {2} test text"
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
illuzor, 2019-09-02
@iLLuzor

String.replace()

B
Bonce, 2019-09-02
@Bonce

You can't ask the server to return a string like this:
{
"text": "Hello %s World %s This is %s test text"
}
Then you can use String.format()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question