🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.java
4 messages
4 total messages Started by J-23 Sun, 27 May 2012 22:53
GSON określony format pomocy
#153450
Author: J-23
Date: Sun, 27 May 2012 22:53
62 lines
2864 bytes
Witam
Mam problem próbuje za pomocą GSON uzyskać takiego JSON: (Poradzcie coś 
bo mi jakoś z JSON nie idzie)

{
     records:[{
                 name:'Middleton, Wendy V.',
                 email:'morbi.tristique@iaculisquis.org',
                 phone:5574291911,
                 state:'TX',
                 zip:'51334'
             },
             {
                 name:'Stark, Olivia P.',
                 email:'urna.suscipit.nonummy@faucibusleo.edu',
                 phone:1666312154,
                 state:'CA',
                 zip:'F8F 6N7'
             },
             {
                 name:'Shannon, Rhea D.',
                 email:'Integer@nibhPhasellusnulla.org',
                 phone:2413489010,
                 state:'IN',
                 zip:'63206'
             },
             {
                 name:'Diaz, August F.',
                 email:'elementum.purus@est.edu',
                 phone:3012535650,
                 state:'MS',
                 zip:'R5J 9C0'
             },
             {
                 name:'Hahn, Garrison B.',
                 email:'Cras.eu.tellus@elementum.edu',
                 phone:3154455608,
                 state:'FL',
                 zip:'F2Y 3W4'
             },
             {
                 name:'Simon, Melanie O.',
                 email:'Curabitur.dictum.Phasellus@venenatisamagna.edu',
                 phone:4025449884,
                 state:'LA',
                 zip:'26268'
             },
             {
                 name:'Morales, Inez E.',
                 email:'mollis@eunullaat.org',
                 phone:5363404748,
                 state:'GA',
                 zip:'9054'
             },
             {
                 name:'Dennis, Desiree Q.',
                 email:'eu.eros.Nam@Nullam.com',
                 phone:4715368003,
                 state:'AK',
                 zip:'N3J 9X4'
             }]
}
Re: GSON określony format pomocy
#153451
Author: Arivald
Date: Mon, 28 May 2012 05:20
67 lines
2780 bytes
W dniu 2012-05-28 00:53, J-23 pisze:
> Witam
> Mam problem próbuje za pomocą GSON uzyskać takiego JSON: (Poradzcie coś
> bo mi jakoś z JSON nie idzie)
>
> {
>      records:[{
>                  name:'Middleton, Wendy V.',
>                  email:'morbi.tristique@iaculisquis.org',
>                  phone:5574291911,
>                  state:'TX',
>                  zip:'51334'
>              },
[...]
>              {
>                  name:'Dennis, Desiree Q.',
>                  email:'eu.eros.Nam@Nullam.com',
>                  phone:4715368003,
>                  state:'AK',
>                  zip:'N3J 9X4'
>              }]
> }

Po pierwsze, ten JSON jest błędny. Detale sprawdź np. tu: 
http://jsonformatter.curiousconcept.com/ , lub dowolnym innym walidatorem.

powinno to wyglądać raczej tak:


  {
       "records":[{
                   "name":"Middleton, Wendy V.",
                   "email":"morbi.tristique@iaculisquis.org",
                   "phone":"5574291911",
                   "state":"TX",
                   "zip":"51334"
               },
[...]
               {
                   "name":"Dennis, Desiree Q.",
                   "email":"eu.eros.Nam@Nullam.com",
                   "phone":"4715368003",
                   "state":"AK",
                   "zip":"N3J 9X4"
               }]
  }


A od strony Javy to nic prostszego (w/g dokumentacji, bo sam używam 
czego innego)...

public class Person {
   public String name;
   public String email;
   public String phone;
   public String state;
   public String zip;
}

public class People {
   public Person[] records;
}

... i serializujesz "People".

-- 
Arivald
Re: GSON określony format pomocy
#153452
Author: Arivald
Date: Mon, 28 May 2012 05:32
20 lines
1672 bytes
W dniu 2012-05-28 07:20, Arivald pisze:
> W dniu 2012-05-28 00:53, J-23 pisze:
>> Witam
>> Mam problem próbuje za pomocą GSON uzyskać takiego JSON: (Poradzcie coś
>> bo mi jakoś z JSON nie idzie)
[...]
> A od strony Javy to nic prostszego (w/g dokumentacji, bo sam używam
> czego innego)...

Przy okazji, GSON szczytem wydajności nie jest...
http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking

[cytat]
Omitted from the first three charts: json/google-gson and scala. These 
serializers are so slow, they would break the scale of our charts.
[/cytat]


-- 
Arivald
Re: GSON określony format pomocy
#153453
Author: J-23
Date: Mon, 28 May 2012 14:13
80 lines
2721 bytes
W dniu 28.05.2012 07:20, Arivald pisze:
> W dniu 2012-05-28 00:53, J-23 pisze:
>> Witam
>> Mam problem próbuje za pomocą GSON uzyskać takiego JSON: (Poradzcie coś
>> bo mi jakoś z JSON nie idzie)
>>
>> {
>> records:[{
>> name:'Middleton, Wendy V.',
>> email:'morbi.tristique@iaculisquis.org',
>> phone:5574291911,
>> state:'TX',
>> zip:'51334'
>> },
> [...]
>> {
>> name:'Dennis, Desiree Q.',
>> email:'eu.eros.Nam@Nullam.com',
>> phone:4715368003,
>> state:'AK',
>> zip:'N3J 9X4'
>> }]
>> }
>
> Po pierwsze, ten JSON jest błędny. Detale sprawdź np. tu:
> http://jsonformatter.curiousconcept.com/ , lub dowolnym innym walidatorem.

nie wiem możliwe ja tego jsona wziałem stad:
http://www.sencha.com/examples-2/data/data.json

Potrzebuje zbudować takiego jsona żebym mógł go wczytać w gridy (robilem 
to jakis czas temu ale skleroza mnie dopadła)


Chodzi o te Grid
http://www.sencha.com/examples-2/#jsongrid
>
> powinno to wyglądać raczej tak:
>
>
> {
> "records":[{
> "name":"Middleton, Wendy V.",
> "email":"morbi.tristique@iaculisquis.org",
> "phone":"5574291911",
> "state":"TX",
> "zip":"51334"
> },
> [...]
> {
> "name":"Dennis, Desiree Q.",
> "email":"eu.eros.Nam@Nullam.com",
> "phone":"4715368003",
> "state":"AK",
> "zip":"N3J 9X4"
> }]
> }
>
>
> A od strony Javy to nic prostszego (w/g dokumentacji, bo sam używam
> czego innego)...
>
> public class Person {
> public String name;
> public String email;
> public String phone;
> public String state;
> public String zip;
> }
>
> public class People {
> public Person[] records;
> }
>
> ... i serializujesz "People".
>

Dzięki ci za przypomnienie

Pozdrawiam
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads