Also, it would be nice to have JSONInt class or something similar.
Thank you,
Alexei
Thanks,
Scott
Here is the code I'm referring to:
public static String escape(String s){
if(s==null)
return null;
StringBuffer sb=new StringBuffer();
for(int i=0;i<s.length();i++){
char ch=s.charAt(i);
switch(ch){
case '"':
sb.append("\\\"");
break;
case '\\':
sb.append("\\\\");
break;
case '\b':
sb.append("\\b");
break;
case '\f':
sb.append("\\f");
break;
case '\n':
sb.append("\\n");
break;
case '\r':
sb.append("\\r");
break;
case '\t':
sb.append("\\t");
break;
case '/':
sb.append("\\/");
break;
default:
if(ch>='\u0000' && ch<='\u001F'){
String ss=Integer.toHexString(ch);
sb.append("\\u");
for(int k=0;k<4-ss.length();k++){
sb.append('0');
}
sb.append(ss.toUpperCase());
}
else{
sb.append(ch);
}
}
}//for
return sb.toString();
}
Alexei
>From JSONString:
public String toString() {
// Backslashes and quotes must be escaped
String s = value;
// replaces \ with \\
s = s.replaceAll("\\\\", "\\\\\\\\");
// replaces " with \"
s = s.replaceAll("\\\"", "\\\\\"");
// wrap the result in quotes
return "\"" + s + "\"";
}