public String toJSON(){
return "{id:"+id+",productname:"+productname+"}";
}
我要返回这种格式的
{
"id":1,
"text":"text1"
}
id的双引号咋加上?
public String toJSON(){
return "{id:"+id+",productname:"+productname+"}";
}
我要返回这种格式的
{
"id":1,
"text":"text1"
}
id的双引号咋加上?
id 后面再拼接个空字符串 "" ,变为字符串类型.
String idStr = id + "";
return "{id:"+ idStr +",productname:"+productname+"}";
return "{id:\""+id+",productname:"+productname+"}";
转义下,斜线不是向左就是向右,记不清楚了。没做过java,感觉这个方法应该是通用的。
15 回答8.4k 阅读
8 回答6.2k 阅读
1 回答4.1k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
2 回答3.1k 阅读
2 回答3.8k 阅读
1 回答2.1k 阅读✓ 已解决
return "{\"id\":" + id + ",\"productname\":\"" + productname + "\"}";
当需要“引号”时,用反斜杠转义,json的键需要,String类型的值也需要,所以放回的时候去掉所有独立双引号,即
{"id": 1 ,"productname":"productname"}