I might be doing something wrong. But i need to solve this error i am getting. I am getting an error when i parse/deserialize json that has white space in the value.
The error message indicates an unterminated JsonObject (denoted by
{}). Perhaps when you removed whitespace, you also fixed a syntax
error in your JSON? It's hard to tell since you've included only a
small, syntactically-invalid snippet of the JSON that you're trying to
parse.
On Wed, Jul 25, 2012 at 2:05 PM, geeg <satyarth.n...@gmail.com> wrote:
> Hi All,
> I might be doing something wrong. But i need to solve this error i am
> getting. I am getting an error when i parse/deserialize json that has white
> space in the value.
> --
> You received this message because you are subscribed to the Google Groups
> "google-gson" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-gson/-/zmxKtkEkl_QJ.
> To post to this group, send email to google-gson@googlegroups.com.
> To unsubscribe from this group, send email to
> google-gson+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-gson?hl=en.
> The error message indicates an unterminated JsonObject (denoted by
> {}). Perhaps when you removed whitespace, you also fixed a syntax
> error in your JSON? It's hard to tell since you've included only a
> small, syntactically-invalid snippet of the JSON that you're trying to
> parse.
> On Wed, Jul 25, 2012 at 2:05 PM, geeg <satyarth.n...@gmail.com> wrote:
> > Hi All,
> > I might be doing something wrong. But i need to solve this error i am
> > getting. I am getting an error when i parse/deserialize json that has
> white
> > space in the value.
> > --
> > You received this message because you are subscribed to the Google Groups
> > "google-gson" group.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msg/google-gson/-/zmxKtkEkl_QJ.
> > To post to this group, send email to google-gson@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-gson+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/google-gson?hl=en.
> --
> You received this message because you are subscribed to the Google Groups
> "google-gson" group.
> To post to this group, send email to google-gson@googlegroups.com.
> To unsubscribe from this group, send email to
> google-gson+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-gson?hl=en.
This shouldn't be parsed as a List<Map<String, String>>, because what
you have is a JsonObject with a nested JsonArray inside that object.
One approach would be:
Another approach to building your own class is to use JsonParser to
fetch a JsonElement from the JSON. Then, you can use the
JsonObject/JsonArray API to pull the information out of the structure.
On Wed, Jul 25, 2012 at 4:55 PM, Satyarth Negi <satyarth.n...@gmail.com> wrote:
> Hi Brandon,
> Thanks for reply. This is what exactly i am trying to send but does not work
> due to white space in "New York"
> msg =
> "{\"ip\":\"184.72.42.15\",\"game\":\"Game\",\"zone\":\"Blitz\",\"rooms\":[{ \"id\":\"901\",\"left\":\"1\",\"maxplayers\":\"300\",\"players\":\"0\",\"ca rds_to_winners\":\"0.12\",\"cards\":\"0\",\"threshold\":\"1\",\"city\":\"Ne w
> York-744662523\"}]}";
> I tried to validate the json in jsonlint.com and it says valid Json. But
> gson gives parsing error.
> Thanks
> On Thu, Jul 26, 2012 at 1:42 AM, Brandon Mintern <mint...@easyesi.com>
> wrote:
>> The error message indicates an unterminated JsonObject (denoted by
>> {}). Perhaps when you removed whitespace, you also fixed a syntax
>> error in your JSON? It's hard to tell since you've included only a
>> small, syntactically-invalid snippet of the JSON that you're trying to
>> parse.
>> On Wed, Jul 25, 2012 at 2:05 PM, geeg <satyarth.n...@gmail.com> wrote:
>> > Hi All,
>> > I might be doing something wrong. But i need to solve this error i am
>> > getting. I am getting an error when i parse/deserialize json that has
>> > white
>> > space in the value.
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "google-gson" group.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msg/google-gson/-/zmxKtkEkl_QJ.
>> > To post to this group, send email to google-gson@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > google-gson+unsubscribe@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/google-gson?hl=en.
>> --
>> You received this message because you are subscribed to the Google Groups
>> "google-gson" group.
>> To post to this group, send email to google-gson@googlegroups.com.
>> To unsubscribe from this group, send email to
>> google-gson+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/google-gson?hl=en.
> --
> You received this message because you are subscribed to the Google Groups
> "google-gson" group.
> To post to this group, send email to google-gson@googlegroups.com.
> To unsubscribe from this group, send email to
> google-gson+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-gson?hl=en.
You are awesome Brandon. It worked.
Actually i was not parsing rooms as <String,String> I was first parsing the
main object as <String,Object> and then parsing rooms part as
<String,String> and it was giving me error. But the way you described it
worked even with white spaces.
Thanks alot.
On Thu, Jul 26, 2012 at 3:03 AM, Brandon Mintern <mint...@easyesi.com>wrote:
> This shouldn't be parsed as a List<Map<String, String>>, because what
> you have is a JsonObject with a nested JsonArray inside that object.
> One approach would be:
> Another approach to building your own class is to use JsonParser to
> fetch a JsonElement from the JSON. Then, you can use the
> JsonObject/JsonArray API to pull the information out of the structure.
> On Wed, Jul 25, 2012 at 4:55 PM, Satyarth Negi <satyarth.n...@gmail.com>
> wrote:
> > Hi Brandon,
> > Thanks for reply. This is what exactly i am trying to send but does not
> work
> > due to white space in "New York"
> > msg =
> "{\"ip\":\"184.72.42.15\",\"game\":\"Game\",\"zone\":\"Blitz\",\"rooms\":[{ \"id\":\"901\",\"left\":\"1\",\"maxplayers\":\"300\",\"players\":\"0\",\"ca rds_to_winners\":\"0.12\",\"cards\":\"0\",\"threshold\":\"1\",\"city\":\"Ne w
> > York-744662523\"}]}";
> > I tried to validate the json in jsonlint.com and it says valid Json. But
> > gson gives parsing error.
> > Thanks
> > On Thu, Jul 26, 2012 at 1:42 AM, Brandon Mintern <mint...@easyesi.com>
> > wrote:
> >> The error message indicates an unterminated JsonObject (denoted by
> >> {}). Perhaps when you removed whitespace, you also fixed a syntax
> >> error in your JSON? It's hard to tell since you've included only a
> >> small, syntactically-invalid snippet of the JSON that you're trying to
> >> parse.
> >> On Wed, Jul 25, 2012 at 2:05 PM, geeg <satyarth.n...@gmail.com> wrote:
> >> > Hi All,
> >> > I might be doing something wrong. But i need to solve this error i am
> >> > getting. I am getting an error when i parse/deserialize json that has
> >> > white
> >> > space in the value.
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "google-gson" group.
> >> > To view this discussion on the web visit
> >> > https://groups.google.com/d/msg/google-gson/-/zmxKtkEkl_QJ.
> >> > To post to this group, send email to google-gson@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > google-gson+unsubscribe@googlegroups.com.
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/google-gson?hl=en.
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "google-gson" group.
> >> To post to this group, send email to google-gson@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> google-gson+unsubscribe@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/google-gson?hl=en.
> > --
> > You received this message because you are subscribed to the Google Groups
> > "google-gson" group.
> > To post to this group, send email to google-gson@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-gson+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/google-gson?hl=en.
> --
> You received this message because you are subscribed to the Google Groups
> "google-gson" group.
> To post to this group, send email to google-gson@googlegroups.com.
> To unsubscribe from this group, send email to
> google-gson+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-gson?hl=en.
If you like that way, using the Message class, I might suggest going
one step further and creating a Room class. That class should have the
fields you want to fetch from the rooms list, and you can give the
variables a more appropriate type. For example:
class Room {
int id;
int left;
int maxplayers;
...
float cards_to_winners;
...
String city;
}
Then, instead of having a List<Map<String, String>> rooms field in
your Message object, you would simply change it to a List<Room>
object.
On Thu, Jul 26, 2012 at 1:14 AM, Satyarth Negi <satyarth.n...@gmail.com> wrote:
> You are awesome Brandon. It worked.
> Actually i was not parsing rooms as <String,String> I was first parsing the
> main object as <String,Object> and then parsing rooms part as
> <String,String> and it was giving me error. But the way you described it
> worked even with white spaces.
> Thanks alot.
> On Thu, Jul 26, 2012 at 3:03 AM, Brandon Mintern <mint...@easyesi.com>
> wrote:
>> This shouldn't be parsed as a List<Map<String, String>>, because what
>> you have is a JsonObject with a nested JsonArray inside that object.
>> One approach would be:
>> Another approach to building your own class is to use JsonParser to
>> fetch a JsonElement from the JSON. Then, you can use the
>> JsonObject/JsonArray API to pull the information out of the structure.
>> On Wed, Jul 25, 2012 at 4:55 PM, Satyarth Negi <satyarth.n...@gmail.com>
>> wrote:
>> > Hi Brandon,
>> > Thanks for reply. This is what exactly i am trying to send but does not
>> > work
>> > due to white space in "New York"
>> > msg =
>> > "{\"ip\":\"184.72.42.15\",\"game\":\"Game\",\"zone\":\"Blitz\",\"rooms\":[{ \"id\":\"901\",\"left\":\"1\",\"maxplayers\":\"300\",\"players\":\"0\",\"ca rds_to_winners\":\"0.12\",\"cards\":\"0\",\"threshold\":\"1\",\"city\":\"Ne w
>> > York-744662523\"}]}";
>> > I tried to validate the json in jsonlint.com and it says valid Json. But
>> > gson gives parsing error.
>> > Thanks
>> > On Thu, Jul 26, 2012 at 1:42 AM, Brandon Mintern <mint...@easyesi.com>
>> > wrote:
>> >> The error message indicates an unterminated JsonObject (denoted by
>> >> {}). Perhaps when you removed whitespace, you also fixed a syntax
>> >> error in your JSON? It's hard to tell since you've included only a
>> >> small, syntactically-invalid snippet of the JSON that you're trying to
>> >> parse.
>> >> On Wed, Jul 25, 2012 at 2:05 PM, geeg <satyarth.n...@gmail.com> wrote:
>> >> > Hi All,
>> >> > I might be doing something wrong. But i need to solve this error i am
>> >> > getting. I am getting an error when i parse/deserialize json that has
>> >> > white
>> >> > space in the value.
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "google-gson" group.
>> >> > To view this discussion on the web visit
>> >> > https://groups.google.com/d/msg/google-gson/-/zmxKtkEkl_QJ.
>> >> > To post to this group, send email to google-gson@googlegroups.com.
>> >> > To unsubscribe from this group, send email to
>> >> > google-gson+unsubscribe@googlegroups.com.
>> >> > For more options, visit this group at
>> >> > http://groups.google.com/group/google-gson?hl=en.
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "google-gson" group.
>> >> To post to this group, send email to google-gson@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> google-gson+unsubscribe@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/google-gson?hl=en.
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "google-gson" group.
>> > To post to this group, send email to google-gson@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > google-gson+unsubscribe@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/google-gson?hl=en.
>> --
>> You received this message because you are subscribed to the Google Groups
>> "google-gson" group.
>> To post to this group, send email to google-gson@googlegroups.com.
>> To unsubscribe from this group, send email to
>> google-gson+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/google-gson?hl=en.
> --
> You received this message because you are subscribed to the Google Groups
> "google-gson" group.
> To post to this group, send email to google-gson@googlegroups.com.
> To unsubscribe from this group, send email to
> google-gson+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-gson?hl=en.
> I want to know how to read a two(A.json,B.json) json file from my android > sdcard then i need to create new json file and write in this file(c.json).