need help regarding double quotes in string

28 views
Skip to first unread message

alan....@bellaliant.net

unread,
May 13, 2013, 7:11:17 PM5/13/13
to googl...@googlegroups.com
Hi Guys,
 
I'm trying to get familiar working with GSON and have attempted the following:
 
output out = new output();
String row0 = "[\"LASTNAME\":\"MacDonald\",\"FIRSTNAME\":\"Terry\",\"EMAIL\":\"tmacd...@someplace.com\"]";
String row1 = "[\"LASTNAME\":\"Fisher\",\"FIRSTNAME\":\"Joyce\",\"EMAIL\":\"jfi...@someplace.com\"]";
out.aaData.add(row0);
out.aaData.add(row1);
    
Gson gson = new Gson();
String json = gson.toJson(out);  
System.out.println( json );
 
**************************************
public class output{
      public String id = "";
      public String error = "";
      public ArrayList<FieldError> fieldErrors = new ArrayList<FieldError>();
      public ArrayList<String[]> data = new ArrayList<String[]>();
      public ArrayList<String[]> row = new ArrayList<String[]>();
      public ArrayList<String> aaData = new ArrayList<String>();
      ...
}
 
The output for this winds up being:
 
{"id":"","error":"","fieldErrors":[],"data":[],"row":[],"aaData":[
[\"LASTNAME\":\"MacDonald\",\"FIRSTNAME\":\"Terry\",\"EMAIL\":\"tmacd...@someplace.com\"],
[\"LASTNAME\":\"Fisher\",\"FIRSTNAME\":\"Joyce\",\"EMAIL\":\"jfi...@someplace.com\"]]}
 
I expected the escaped character "\" to disappear and just leave the double quote, but it didn't.  The format must be: "field_name":"field_value" .  I even tried escaping the escape character with \\" and even \\\".  None of these worked.  What do I need to do to get the format I want?  Please advise.
 
Alan
Reply all
Reply to author
Forward
0 new messages