{"key1":"value1","key2":"value2","key3":"value3"}如何转换成{"Data":{"key1":"value1","key2":"value2","key3":"value3"}},用Java语言实现
时间: 2023-10-01 22:07:26 浏览: 75
JAVA数据类型转换
5星 · 资源好评率100%
{"key1":"value1","key2":"value2","key3":"value3"}可以通过以下Java代码实现转换成{"Data":{"key1":"value1","key2":"value2","key3":"value3"}}:
```java
import com.google.gson.JsonObject;
public class Main {
public static void main(String[] args) {
JsonObject jsonObject = new JsonObject();
JsonObject dataObject = new JsonObject();
jsonObject.addProperty("key1", "value1");
jsonObject.addProperty("key2", "value2");
jsonObject.addProperty("key3", "value3");
dataObject.add("Data", jsonObject);
System.out.println(dataObject);
}
}
```
阅读全文