• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Convert List To Json Data

 
Greenhorn
Posts: 25
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have list of object and i want convert in specific formatted json as follows..
{
"Result":"OK",
"Records":[
{"PersonId":1,"Name":"Benjamin Button","Age":17,"RecordDate":"\/Date(1320259705710)\/"},
{"PersonId":2,"Name":"Douglas Adams","Age":42,"RecordDate":"\/Date(1320259705710)\/"},
{"PersonId":3,"Name":"Isaac Asimov","Age":26,"RecordDate":"\/Date(1320259705710)\/"},
{"PersonId":4,"Name":"Thomas More","Age":65,"RecordDate":"\/Date(1320259705710)\/"}
]
}

my current code is


and my current output is

+++[[100,"CWR",null,null,"11","B5A","IC",0,null,null,null,null,null,null],[20,"LO",null,null,"11","B5A","IH",0,null,null,null,null,null,null],[15,"RP",null,null,"555","B5A","IC",0,null,null,null,null,null,null],[15,"CWR",null,null,"22","B5A","IC",0,null,null,null,null,null,null]]



is there any solution ??
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You really want to clean up that code (especially that looooong line). Oh and use code tags here, they make reading code a lot easier.

Also, what is JSONObject? One of your own classes, or a part of some framework? Apparently that class is supposed to create the JSON, but without knowing more how it works, its impossible to tell why it creates the output you see.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@bharat salunkhe: Please UseCodeTags (← click) and use lines of less than 120 chars when posting code as it makes it easier for people to read your code. I've sorted it for you this time.
 
reply
    Bookmark Topic Watch Topic
  • New Topic