aspose file tools*
The moose likes Java in General and the fly likes Creating JSON document using foreach loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Creating JSON document using foreach loop" Watch "Creating JSON document using foreach loop" New topic
Author

Creating JSON document using foreach loop

Tarun Oohri
Ranch Hand

Joined: Feb 20, 2013
Posts: 175
Hello Everyone,
I am trying to fetch the data from the database and then trying to set the values in the JSON document using ArrayList but i am not able to do that.
Lets say this is hard code JSON which i want to convert it into dynamic JSON
Now, to embed the JSON rows dynamically , i have used ArrayList as follows :Now i want to embed this collection into the JSON document. but not sure how to do this.
Please Guide me to get through this....Thanks !!!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Create a StringBuilder. First append the start, then loop and append each row. After the loop, append the end. Then convert to String using (well-named) toString().


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tarun Oohri
Ranch Hand

Joined: Feb 20, 2013
Posts: 175
Hi Rob, Thanks for replying . I tried to do that but i am getting compile time errors. Can you please make it for me :/
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Why don't you show us your current code and the compiler errors instead?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating JSON document using foreach loop