我有一个来自服务器的复杂JSON需要转换为java对象。
{"menus":[{"title":"Jewellery","menu_columns":[{"title":"category","menu_items":[{"title":"Earrings"},{"title":"Necklaces"},{"title":"Necklace Sets"},{"title":"Anklets"},{"title":"Mangalsutra"},{"title":"Pendants"},{"title":"Bangles \u0026 Bracelets"},{"title":"Rings"},{"title":"Maang Tikka"},{"title":"Keychains"},{"title":"Baju Band"},{"title":"Brooch"},{"title":"Hair Pins"},{"title":"Jewellery Box"},{"title":"Nose Ring"},{"title":"Waist Belts"},{"title":"Jewellery Combo"},{"title":"Watches"},{"title":"Other"}]},{"title":"Type","menu_items":[{"title":"Bridal Jewellery"},{"title":"Temple Jewellery"},{"title":"Statement Jewellery"},{"title":"Thewa Jewellery"},{"title":"Handmade Jewellery"},{"title":"Filigree Jewellery"},{"title":"Pearl Jewellery"},{"title":"High End Jewellery"},{"title":"Ethnic Jewellery"},{"title":"Kundan Jewellery"},{"title":"Jhumkas"}]},{"title":"Earrings","menu_items":[]}]},{"title":"Sarees","menu_columns":[{"title":"by fabric","menu_items":[{"title":"Cotton Sarees"},{"title":"Art Silk Sarees"},{"title":"Georgette Sarees"},{"title":"Chiffon Sarees"},{"title":"Net Sarees"},{"title":"Crepe Sarees"},{"title":"Silk Sarees"},{"title":"Viscose Sarees"},{"title":"Tissue Sarees"},{"title":"Satin Sarees"},{"title":"Velvet Sarees"},{"title":"Jute Sarees"},{"title":"Brasso Sarees"},{"title":"Shimmer Sarees"},{"title":"Brocade Sarees"},{"title":"Jacquard Sarees"},{"title":"Dupion Sarees"},{"title":"Saree Blouses"},{"title":"Sarees Combo"}]},{"title":"by type","menu_items":[{"title":"Supernet Sarees"},{"title":"Banarasi Sarees"},{"title":"Banarasi Silk Sarees"},{"title":"Kalamkari Sarees"},{"title":"Chanderi Sarees"},{"title":"Tussar Silk Sarees"},{"title":"Organza Sarees"},{"title":"Wedding Sarees"},{"title":"Printed Sarees"},{"title":"Lehenga Sarees"},{"title":"Bhagalpuri Silk Sarees"},{"title":"Heavy Work Sarees"},{"title":"Party Wear Sarees"},{"title":"Traditional Sarees"},{"title":"One Minute Sarees"},{"title":"Kerala Sarees"},{"title":"Bandhani Sarees"},{"title":"Ikat Sarees"},{"title":"Hand Woven Sarees"}]},{"title":"bollywood sarees","menu_items":[{"title":"Kareena Kapoor Sarees"},{"title":"Katrina Kaif Saree"},{"title":"Madhuri Dixit Sarees"},{"title":"Deepika Padukone Saree"},{"title":"Priyanka Chopra Saree"},{"title":"Sridevi Sarees"},{"title":"Anushka Sharma Saree"},{"title":"Shilpa Shetty Sarees"},{"title":"Sonakshi Sinha Saree"},{"title":"Bipasha Basu Sarees"},{"title":"Aishwarya Rai Saree"},{"title":"Sonam Kapoor Saree"},{"title":"Vidya Balan Saree"}]}]},{"title":"Salwar Kameez","menu_columns":[{"title":"","menu_items":[{"title":"Dress Materials"},{"title":"Anarkali Salwar Kameez"},{"title":"Cotton Salwar Kameez"},{"title":"Party Wear Salwar Kameez"},{"title":"Pakistani"},{"title":"Wedding"},{"title":"Salwars \u0026 Churidars"},{"title":"Semi Stitched Salwar Suits"},{"title":"Bollywood Salwars"},{"title":"Salwar Combo"}]}]},{"title":"More","menu_columns":[{"title":"bridal","menu_items":[{"title":"Bridal Sets"},{"title":"Bridal Lehengas"},{"title":"Bridal Sarees"}]},{"title":"lehengas","menu_items":[{"title":"Ghagra Choli"},{"title":"Lehenga Choli"},{"title":"Bollywood Lehengas"}]},{"title":"bags","menu_items":[{"title":"Hand Bags"},{"title":"Clutches"},{"title":"Wallets"},{"title":"Tote Bags"},{"title":"Backpacks"},{"title":"Sling Bags"},{"title":"Potli Bags"}]},{"title":"other apparel","menu_items":[{"title":"Kurtas \u0026 Kurtis"},{"title":"Tops"},{"title":"Stoles \u0026 Dupattas"},{"title":"Tunics"},{"title":"Leggings"},{"title":"Shawls"},{"title":"Dresses"},{"title":"Skirts"}]}]},{"title":"Home Decor","menu_columns":[{"title":"accessories","menu_items":[{"title":"Wall Decals"},{"title":"Wall Clocks"},{"title":"Ipad Covers"},{"title":"Laptop Skins"},{"title":"Phone Cases"},{"title":"Candles"},{"title":"Flowers"},{"title":"Artificial Flowers"},{"title":"Table Lamps"},{"title":"Trays"},{"title":"Vases"},{"title":"Wall Art"},{"title":"Tea Kettle"},{"title":"Paintings"},{"title":"Stationery"},{"title":"Photo Frames"},{"title":"Decorative Plates"},{"title":"Pots"},{"title":"Sculptures"},{"title":"Other"}]},{"title":"furnishing","menu_items":[{"title":"Pillow Covers"},{"title":"Bed Sheets"},{"title":"Duvet Covers"},{"title":"Quilts"},{"title":"Table Cloth"},{"title":"Table Mats \u0026 Runner"},{"title":"Carpets"},{"title":"Jaipuri Razai"},{"title":"Other"}]}]},{"title":"Gifts","menu_columns":[{"title":"by recipients","menu_items":[{"title":"For Him"},{"title":"For Her"},{"title":"For Kids"},{"title":"For Dad"},{"title":"For Mom"},{"title":"For Husband"},{"title":"For Wife"},{"title":"For Boyfriend"},{"title":"For Girlfriend"},{"title":"For Brother"},{"title":"For Sister"}]},{"title":"by occasions","menu_items":[{"title":"Birthday"},{"title":"Engagement"},{"title":"Wedding"},{"title":"Anniversary"},{"title":"Congratulation"},{"title":"House Warming"},{"title":"Office Opening"}]},{"title":"by festivals","menu_items":[{"title":"Christmas Gifts"},{"title":"Christmas Decorations"},{"title":"Valentine Gifts"},{"title":"Ganesh Chaturthi"},{"title":"Rakhi Online"},{"title":"New Year"},{"title":"Teachers Day"},{"title":"Engineers Day"},{"title":"Thanksgiving"},{"title":"Onam gifts"},{"title":"Navratri lehenga Chaniya Choli"},{"title":"Diwali Gifts"}]}]},{"title":"Lehenga","menu_columns":[]}]}
我想节省手动编写与这种复杂JSON相对应的Java对象(模型)的时间。
是否有任何工具可以帮助您快速将这个复杂的JSON转换为Java模型?
我查看了http://www.jsonschema2pojo.org/,但我认为它没有生成正确的Java POJO。我不是在寻找用于将JSON转换为java对象的库(如GSON,Jackson),而是用于生成java模型类的在线工具。
答案 0 :(得分:0)
我写了一个简单的JavaScript工具来自动生成java类文件。它仅适用于Chrome浏览器。这是链接:
答案 1 :(得分:-2)
你能看看Gson API吗?我目前正在我的项目中使用它,它对我来说很好......
答案 2 :(得分:-2)
想想杰克逊图书馆。 只需使用ObjectMapper readValue()和writeValue()
即可我过去发现的最佳解释是:http://www.mkyong.com/java/how-to-convert-java-object-to-from-json-jackson