• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating JSON document using foreach loop

 
Tarun Oohri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20559
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Tarun Oohri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20559
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you show us your current code and the compiler errors instead?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic