sangmingming / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

how to convert JsonObject to JSONString()? #154

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
call JsonObject.toString()  result is not a realy JSONString
because some char is not quoted!!!
Gson gson = new Gson();
JsonParser p = new JsonParser();

JsonElement r = p.parse("{\"text\":\"good\\n after\\nnoom\"}");
JsonObject ob = r.getAsJsonObject();

r.toString() \\ espect {"text":"good\\n after\\nnoom\"} but {"text":"good
after
noom\"}

Original issue reported on code.google.com by lxb...@gmail.com on 9 Sep 2009 at 9:56

GoogleCodeExporter commented 9 years ago
Issue 157 has been merged into this issue.

Original comment by joel.leitch@gmail.com on 23 Sep 2009 at 5:27

GoogleCodeExporter commented 9 years ago
I will create a change to fix this to at least use the basic escaping according 
to
the JSON spec.

Since the Gson object can be configured to do extra escaping (i.e. HTML, JS, 
etc.),
you can always use the following method to generate valid JSON from some 
JsonElement
object:
{@link Gson#toJson(JsonElement)}

Original comment by joel.leitch@gmail.com on 23 Sep 2009 at 5:31

GoogleCodeExporter commented 9 years ago
Fix submitted with r446.

Original comment by joel.leitch@gmail.com on 23 Sep 2009 at 6:28

GoogleCodeExporter commented 9 years ago
Issue 107 has been merged into this issue.

Original comment by joel.leitch@gmail.com on 23 Sep 2009 at 6:49