StringBuffer问题
Java code
public static void main(String[] args)
{
String a = "{\"deviceList\":[{\"deviceAliasName\":\"QQ\",\"deviceID\":\"lifanghua11\",\"deviceType\":\"1\",\"terminalType\":\"terminaltype\"}],\"returnCode\":\"0\",\"returnDesc\":\"Success\"}";
StringBuffer buffer = new StringBuffer(a);
buffer.insert(a.indexOf("["), "@");
buffer.insert(a.lastIndexOf("]")
+ NumContants.TWO.getValue(), "@");
System.out.println(a.toString());
}
为什么输出地结果是:{"deviceList":[{"deviceAliasName":"QQ","deviceID":"lifanghua11","deviceType":"1","terminalType":"terminaltype"}],"returnCode":"0","returnDesc":"Success"}
@没有加上去.新人,求指点
------解决方案--------------------System.out.println(buffer);
------解决方案--------------------StringBuffer对象已经改变了,但是String a是没有改变的,呵呵。
楼主小心了。
------解决方案--------------------楼主粗心了,你最后输出的是a啊,不是buffer,要检查检查……
------解决方案--------------------System.out.println(buffer.toString());
------解决方案-------------------- String a = "{\"deviceList\":[{\"deviceAliasName\":\"QQ\",\"deviceID\":\"lifanghua11\",\"deviceType\":\"1\",\"terminalType\":\"terminaltype\"}],\"returnCode\":\"0\",\"returnDesc\":\"Success\"}";
StringBuffer buffer = new StringBuffer(a);
buffer.insert(a.indexOf("["), "@");
buffer.insert(a.lastIndexOf("]")
+ NumContants.TWO.getValue(), "@");
System.out.println(a.toString());
代码没有问题,输出的不是自己的结果。。。