Google Groups Home
Help | Sign in
json string escapes
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
sluramod  
View profile
 More options Aug 16 2006, 1:50 pm
From: "sluramod" <alexei.soko...@gmail.com>
Date: Wed, 16 Aug 2006 17:50:06 -0000
Local: Wed, Aug 16 2006 1:50 pm
Subject: json string escapes
Please fix a bug with string escapes. Use code published here
http://www.JSON.org/java/json_simple.zip as a reference.

Also, it would be nice to have JSONInt class or something similar.

Thank you,
Alexei


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Blum  
View profile
 More options Aug 16 2006, 4:20 pm
From: "Scott Blum" <sco...@google.com>
Date: Wed, 16 Aug 2006 20:20:12 -0000
Local: Wed, Aug 16 2006 4:20 pm
Subject: Re: json string escapes
Would you mind describing the particular bug you have in mind?

Thanks,
Scott


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sluramod  
View profile
 More options Aug 16 2006, 5:21 pm
From: "sluramod" <alexei.soko...@gmail.com>
Date: Wed, 16 Aug 2006 14:21:38 -0700
Local: Wed, Aug 16 2006 5:21 pm
Subject: Re: json string escapes
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
vsmak  
View profile
 More options Aug 17 2006, 4:02 pm
From: "vsmak" <vees...@gmail.com>
Date: Thu, 17 Aug 2006 13:02:31 -0700
Local: Thurs, Aug 17 2006 4:02 pm
Subject: Re: json string escapes
Strings with escaped characters aren't written out properly because
JSONString's toString() only replaces the character '\\' and not other
escaped characters like '\n', '\r', etc.

>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 + "\"";
          }

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Blum  
View profile
(1 user)  More options Aug 17 2006, 11:07 pm
From: "Scott Blum" <sco...@google.com>
Date: Thu, 17 Aug 2006 23:07:40 -0400
Local: Thurs, Aug 17 2006 11:07 pm
Subject: Re: json string escapes

Thanks, guys.  We'll get right on this.

Scott


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google