Skip to content
Advertisement

How to put multiple values into a json in java

I’m trying to return a list of values from JDBC but multiple columns of the database to solve this I just made a JSON object to make something like this

JavaScript

The issue is im getting this error WARN 43953 --- [nio-1900-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]

What I’ve tried

I’ve tried using a hash map but it doesn’t work and I don’t even know if it can return the value like a want it.

What I hope

I hope at the end I can get a list of values similar to the way I showed above, all separate. This is to be displayed on HTML later so if I’m doing something i shouldn’t also let me know

This is my code

JavaScript

pom.xml

JavaScript

What I tried

JavaScript

Traceback

JavaScript

Advertisement

Answer

You should work with a List instead putting the values inside an object and increasing the counter variable. I would suggest you use something like this

JavaScript

Your output will look slightly different.

JavaScript

It is however better to work with lists/arrays. Otherwise you wold have to access your result by incrementing variables until an error is thrown or something like this.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement