JSONObject.toJSONString(xxx)转换后是一个json对象,我只想要json字符串
{
"propValue": [{"min": 6.0,"max": 6.0,"step": 1.0}]
}
想要这样的
{
"propValue": "[{\"min\": 6.0,\"max\": 6.0,\"step\": 1.0}]"
}
您好,根据JSON定义
[{"min": 6.0,"max": 6.0,"step": 1.0}]
这一块代码表示的是你实体上的propValue字段是一个数组包含了对象,大概class是这样的
public @Data class TestClass{
private List<Info> propValue;
}
@Data class Info{
private double min;
private double max;
private double step;
}
// 这样的实体结构转换一定是一个JSON格式如果您非要采用字符串格式那么可改变实体对象
public @Data class TestClass{
private String propValue;
}
// 将propValue类型编程String类型即可
如果不想采用改变实体的方式来,可以使用JSONObject方法put一个propValue 值为JSON.toJSONString(xxx.getPropValue()) 然后在转换成一个JSON就是你想要的JSON对象了
@hi1027 如果这对您有所帮助,或者解决了您的问题,是否可以关闭此问题?
Most helpful comment
您好,根据JSON定义
这一块代码表示的是你实体上的propValue字段是一个数组包含了对象,大概class是这样的