Create josn Array in java Servlet using JSON

This question already has an answer here:

  • How do you return a JSON object from a Java Servlet 10 answers

  • its Very easy actually. Use Google gson.jar Either you download From Here Download Google GSON Jar OR add dependencies( if Your Project is Maven ) to your pom.xml

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.2</version>
    </dependency>
    

    and try this Link GSON Serializer Example

    Note :- This is just a reference code. You can Implement at your own way as per your Need. Thank You


    Create a POJO which represents your JSON object. Top object containing list of second object. Use jackson or xstream to marshal Java object into Json and write the json string onto servlet response.

    链接地址: http://www.djcxy.com/p/46062.html

    上一篇: 显示从java servlet到jsp的数据库数据为json

    下一篇: 使用JSON在java Servlet中创建josn数组