简体   繁体   English

如何在JSON字符串中用大括号替换大括号?

[英]How can I replace curly braces with a real value inside a JSON string?

I'm developing an Android project. 我正在开发一个Android项目。 In development I use Retrofit, Gson, RxJava. 在开发中,我使用Retrofit,Gson,RxJava。

For example, such an answer may return from my server and I must replace the curly braces with real values. 例如,这样的答案可能会从我的服务器返回,并且我必须用大括号替换大括号。

{
    "text": "Hello {0} World {1} This is {2} test text"
}

You can use MessageFormat like so: 您可以像这样使用MessageFormat

import java.text.MessageFormat;
MessageFormat.format("Hello {0} World {1} This is {2} test text", var1, var2, var3)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM