Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用java中的另一个字符串替换JSON对象中的JSON元素?_Java_Json - Fatal编程技术网

如何用java中的另一个字符串替换JSON对象中的JSON元素?

如何用java中的另一个字符串替换JSON对象中的JSON元素?,java,json,Java,Json,JSON对象: { "test1":"2", "test2":"4", "test3":"5" } 我需要将“test2”:“4”替换为“test2”:“这是测试” 如何使用Java实现这一点 我需要将“test2”:“4”替换为“这是test”字符串 如何使用java实现这一点 使用,例如,记住: 你需要 如果要将字符串“test2”:“4”替换为“this is test”,则会使json不可解析,如果要将键“test2”的内容从“4”更改为“this is test”

JSON对象:

{
  "test1":"2",
  "test2":"4",
  "test3":"5"
}
我需要将
“test2”:“4”
替换为
“test2”:“这是测试”

如何使用Java实现这一点

我需要将
“test2”:“4”
替换为
“这是test”
字符串

如何使用java实现这一点

使用,例如,记住:

  • 你需要


如果要将字符串“test2”:“4”替换为“this is test”,则会使json不可解析,如果要将键“test2”的内容从“4”更改为“this is test”,则可以使用json解析器API,如或等

  String result = yourJsonString.replace("\"test2\":\"4\"", "\"test2\":\"this is test\"");