Correct way for parsing JSON objects containing arrays in Java Servlets (with Gson for example)

后端 未结 3 1713
别那么骄傲
别那么骄傲 2020-12-16 05:35

I know this is a topic much talked about, but I still wasn\'t able to find a correct and clear answer to my specific problem.

I\'ve got a JSON that looks like this:<

3条回答
  •  一生所求
    2020-12-16 06:05

    In the real world you typically wouldn't send an actual json object to a servlet and you won't often handle populating values from a request in most circumstances. JSON is JavaScript object notation - and it's great when consumed for use in client side coding.

    It's easier to use query string for params rather than a post with json (which it appears you are actually doing). host/url?gameId=5&nrPlayers=2

    As far as how to populate values, convention-over-configuration is the way to go for cleanest code. You can use a frameworks like struts to offload all of the transfer of values onto the framework. Not sure what your whole application looks, your intention for writing (ie writing servlets from scratch is a great way to learn but not common practice in real application development environments) like so this may or may not be a helpful answer.

提交回复
热议问题