java - Unable to build this Complex JSON Structure -
i have inter-related maps representing below data .
{ "soft drinks": { "tin": [ { "lean apple": [ { "name": "1 litre" }, { "name": "2 litre" } ] }, { "clear": [ { "name": "7 litre" }, { "name": "10 litre" } ] } ], "bottled": [ ] } }
this code representing above json data in form of java code
package test;
import java.util.linkedhashmap; import java.util.linkedlist; import java.util.map; import org.json.jsonexception; import org.json.jsonobject; public class post { public static void main(string args[]) throws jsonexception { linkedlist<string> fortinitemslist = new linkedlist<string>(); linkedlist<string> forbottleitemslist = new linkedlist<string>(); jsonobject jsonobj = new jsonobject(); map<string,linkedlist<string>> categoryitemsmap = new linkedhashmap<string,linkedlist<string>>(); fortinitemslist.add("lean apple"); fortinitemslist.add("clear"); forbottleitemslist.add("lemon"); forbottleitemslist.add("clear"); categoryitemsmap.put("tin", fortinitemslist); categoryitemsmap.put("bottled", forbottleitemslist); // completion of categories. map<string,linkedlist<string>> subcategory = new linkedhashmap<string,linkedlist<string>>(); linkedlist<string> forlemonitems = new linkedlist<string>(); forlemonitems.add("1 litre"); forlemonitems.add("2 litre"); subcategory.put("lemon", forlemonitems); linkedlist<string> forclearitems = new linkedlist<string>(); forclearitems.add("7 litre"); forclearitems.add("10 litre"); subcategory.put("clear", forclearitems); (map.entry<string, linkedlist<string>> entry : categoryitemsmap.entryset()) { string key = entry.getkey(); linkedlist<string> list = entry.getvalue(); for(string value : list) { system.out.println(key+"\t"+value); } //jsonobj.put(entry, arg1); } } }
could please tell me how can build above json structure ??
i trying different things m, unsuccessful , problem facing getting bottled array filling same tin array items .
to give idea of unholy abomination things become if did way: here's data structure have create capture json propose.
map<string, map<string, list<map<string, list<map<string, string>>>>>> items;
so, feel free implement this, if me, build data model , map jackson.
Comments
Post a Comment