-4

i want to create a json data to parse to service as a string, e.g. http://xyzabc.com/pos/getstatus?parse=mystring

That string has to contain the data below. I have this data in the arraylist as a same name.

    {
    "ticket": "1-0006",
    "saleID": "140704131457005701",
    "tableid": 41,
    "status": 141,
    "total": "45.140",
    "layoutid": 2,
    "tablename": "66",
    "noofcustomer": 2,
    "userid": 1,
    "ordertype": 210,
    "istaxexcemt": 0,
    "gratuityid": "",
    "gratuitypercentage": "",
    "generatedon": "",
    "isprintonbill": "",
    "products": [
        {
            "menuitemid": 349,
            "qty": "1",
            "price": 2,
            "price2": 2,
            "seatid": 1,
            "status": "141",
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 7.5,
            "taxids": [
                {
                    "taxid": "1",
                    "taxpercent": "7.5",
                    "Amount": 0.15
                }
            ],
            "taxamount": 0.15,
            "seatname": "Seat 1",
            "shiftlevelid": "",
            "reason": "",
            "coursingid": "2",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "20140704131457011",
            "menuitemname": "Cherry Coke",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        },
        {
            "menuitemid": 44,
            "qty": "1",
            "price": 1.79,
            "price2": 1.79,
            "seatid": 1,
            "status": "141",
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 7.5,
            "taxids": [
                {
                    "taxid": "1",
                    "taxpercent": "7.5",
                    "Amount": 0.13425
                }
            ],
            "taxamount": 0.13425,
            "seatname": "Seat 1",
            "shiftlevelid": "",
            "reason": "",
            "coursingid": "2",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "20140704131457012",
            "menuitemname": "Sweet Tea",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        },
        {
            "menuitemid": 43,
            "qty": "1",
            "price": 1.79,
            "price2": 1.79,
            "seatid": 1,
            "status": "141",
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 7.5,
            "taxids": [
                {
                    "taxid": "1",
                    "taxpercent": "7.5",
                    "Amount": 0.13425
                }
            ],
            "taxamount": 0.13425,
            "seatname": "Seat 1",
            "shiftlevelid": "",
            "reason": "",
            "coursingid": "2",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "20140704131457013",
            "menuitemname": "Unsweet Tea",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        },
        {
            "menuitemid": 3,
            "qty": "1",
            "price": 8.95,
            "price2": 15.95,
            "seatid": 1,
            "status": "141",
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 7.5,
            "taxids": [
                {
                    "taxid": "1",
                    "taxpercent": "7.5",
                    "Amount": 0.67125
                }
            ],
            "taxamount": 1.19625,
            "seatname": "Seat 1",
            "shiftlevelid": "",
            "reason": "",
            "coursingid": "8",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [
                {
                    "modifierid": "29",
                    "modifierqty": "1",
                    "modifierprice": "1",
                    "modifiergroupid": "24",
                    "modifierslice": "0",
                    "TaxAmount": "0.075",
                    "taxpercentage": "7.5",
                    "pizzasliceid": "0",
                    "ModPref": "Extra",
                    "ModPrefid": 4,
                    "modtaxLst": [
                        {
                            "taxid": "1",
                            "taxpercent": "7.5",
                            "Amount": 0.075
                        }
                    ]
                },
                {
                    "modifierid": "30",
                    "modifierqty": "1",
                    "modifierprice": "2.5",
                    "modifiergroupid": "24",
                    "modifierslice": "0",
                    "TaxAmount": "0.1875",
                    "taxpercentage": "7.5",
                    "pizzasliceid": "0",
                    "ModPref": "",
                    "ModPrefid": 0,
                    "modtaxLst": [
                        {
                            "taxid": "1",
                            "taxpercent": "7.5",
                            "Amount": 0.1875
                        }
                    ]
                },
                {
                    "modifierid": "35",
                    "modifierqty": "1",
                    "modifierprice": "0.5",
                    "modifiergroupid": "24",
                    "modifierslice": "0",
                    "TaxAmount": "0.0375",
                    "taxpercentage": "7.5",
                    "pizzasliceid": "0",
                    "ModPref": "",
                    "ModPrefid": 0,
                    "modtaxLst": [
                        {
                            "taxid": "1",
                            "taxpercent": "7.5",
                            "Amount": 0.0375
                        }
                    ]
                },
                {
                    "modifierid": "38",
                    "modifierqty": "1",
                    "modifierprice": "0.5",
                    "modifiergroupid": "24",
                    "modifierslice": "0",
                    "TaxAmount": "0.0375",
                    "taxpercentage": "7.5",
                    "pizzasliceid": "0",
                    "ModPref": "",
                    "ModPrefid": 0,
                    "modtaxLst": [
                        {
                            "taxid": "1",
                            "taxpercent": "7.5",
                            "Amount": 0.0375
                        }
                    ]
                },
                {
                    "modifierid": "43",
                    "modifierqty": "1",
                    "modifierprice": "2.5",
                    "modifiergroupid": "24",
                    "modifierslice": "0",
                    "TaxAmount": "0.1875",
                    "taxpercentage": "7.5",
                    "pizzasliceid": "0",
                    "ModPref": "",
                    "ModPrefid": 0,
                    "modtaxLst": [
                        {
                            "taxid": "1",
                            "taxpercent": "7.5",
                            "Amount": 0.1875
                        }
                    ]
                }
            ],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "20140704131457014",
            "menuitemname": "Crab And Shrimp Dip",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        },
        {
            "menuitemid": 44,
            "qty": "1",
            "price": 1.79,
            "price2": 1.79,
            "seatid": 1,
            "status": "141",
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 7.5,
            "taxids": [
                {
                    "taxid": "1",
                    "taxpercent": "7.5",
                    "Amount": 0.13425
                }
            ],
            "taxamount": 0.13425,
            "seatname": "Seat 1",
            "shiftlevelid": "",
            "reason": "",
            "coursingid": "2",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "20140704131517017",
            "menuitemname": "Sweet Tea",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        },
        {
            "menuitemid": 41,
            "qty": "1",
            "price": 1.79,
            "price2": 1.79,
            "seatid": 1,
            "status": "141",
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 7.5,
            "taxids": [
                {
                    "taxid": "1",
                    "taxpercent": "7.5",
                    "Amount": 0.13425
                }
            ],
            "taxamount": 0.13425,
            "seatname": "Seat 1",
            "shiftlevelid": "",
            "reason": "",
            "coursingid": "2",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "20140704142217017",
            "menuitemname": "Lemonade",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        },
        {
            "menuitemid": 244,
            "qty": "1",
            "price": 1.95,
            "price2": 1.95,
            "seatid": 1,
            "status": 139,
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 0,
            "taxids": [],
            "taxamount": 0.0001,
            "seatname": "Seat 1",
            "shiftlevelid": "",
            "reason": "not tastier",
            "coursingid": "24",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "201407041314570110",
            "menuitemname": "S. Bread",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        },
        {
            "menuitemid": 277,
            "qty": "1",
            "price": 8,
            "price2": 8,
            "seatid": 1,
            "status": "141",
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 0,
            "taxids": [],
            "taxamount": 0.0001,
            "seatname": "Seat 1",
            "shiftlevelid": "",
            "reason": "",
            "coursingid": "24",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "201407041314570111",
            "menuitemname": "S. S.F. SAL",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        },
        {
            "menuitemid": 280,
            "qty": "1",
            "price": 1.95,
            "price2": 2.45,
            "seatid": 1,
            "status": "141",
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 0,
            "taxids": [],
            "taxamount": 0.0001,
            "seatname": "Seat 1",
            "shiftlevelid": "",
            "reason": "",
            "coursingid": "24",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [
                {
                    "modifierid": "182",
                    "modifierqty": "1",
                    "modifierprice": "0.5",
                    "modifiergroupid": "31",
                    "modifierslice": "0",
                    "TaxAmount": "0",
                    "taxpercentage": "0",
                    "pizzasliceid": "0",
                    "ModPref": "Extra",
                    "ModPrefid": 4,
                    "modtaxLst": []
                }
            ],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "201407041314570112",
            "menuitemname": "S. Sd. Sal.",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        },
        {
            "menuitemid": 44,
            "qty": "1",
            "price": 1.79,
            "price2": 1.79,
            "seatid": 2,
            "status": "141",
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 7.5,
            "taxids": [
                {
                    "taxid": "1",
                    "taxpercent": "7.5",
                    "Amount": 0.13425
                }
            ],
            "taxamount": 0.13425,
            "seatname": "Seat 2",
            "shiftlevelid": "",
            "reason": "",
            "coursingid": "2",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "201407041422510110",
            "menuitemname": "Sweet Tea",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        },
        {
            "menuitemid": 44,
            "qty": "1",
            "price": 1.79,
            "price2": 1.79,
            "seatid": 2,
            "status": "141",
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 7.5,
            "taxids": [
                {
                    "taxid": "1",
                    "taxpercent": "7.5",
                    "Amount": 0.13425
                }
            ],
            "taxamount": 0.13425,
            "seatname": "Seat 2",
            "shiftlevelid": "",
            "reason": "",
            "coursingid": "2",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "20140704142251017",
            "menuitemname": "Sweet Tea",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        },
        {
            "menuitemid": 44,
            "qty": "1",
            "price": 1.79,
            "price2": 1.79,
            "seatid": 2,
            "status": "141",
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 7.5,
            "taxids": [
                {
                    "taxid": "1",
                    "taxpercent": "7.5",
                    "Amount": 0.13425
                }
            ],
            "taxamount": 0.13425,
            "seatname": "Seat 2",
            "shiftlevelid": "",
            "reason": "",
            "coursingid": "2",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "20140704142251018",
            "menuitemname": "Sweet Tea",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        },
        {
            "menuitemid": 44,
            "qty": "1",
            "price": 1.79,
            "price2": 1.79,
            "seatid": 2,
            "status": "141",
            "holdtime": 0,
            "istaxexcemt": 0,
            "taxpercent": 7.5,
            "taxids": [
                {
                    "taxid": "1",
                    "taxpercent": "7.5",
                    "Amount": 0.13425
                }
            ],
            "taxamount": 0.13425,
            "seatname": "Seat 2",
            "shiftlevelid": "",
            "reason": "",
            "coursingid": "2",
            "istaxinclude": "0",
            "ordertype": "210",
            "modifiers": [],
            "saleid": "140704131457005701",
            "SaleDetailsMenuItem_ID": "20140704142251019",
            "menuitemname": "Sweet Tea",
            "timeeventid": "",
            "discountamount": "0",
            "definitiontype": "",
            "discountreason": "",
            "discountistaxadjust": 1,
            "discounttax": "0",
            "discountpercentage": 0,
            "discountshiftlevelid": ""
        }
    ],
    "checktimeeventid": "",
    "checkdiscountamount": "0",
    "checkdefinitiontype": "",
    "checkdiscountreason": "",
    "checkdiscountistaxadjust": 1,
    "checkdiscounttax": "0",
    "checkdiscountpercentage": 0,
    "checkdiscountshiftlevelid": "",
    "customerid": "0"
}

please anyone help me to solve this.

Mark
  • 2,380
  • 11
  • 29
  • 49
user3789180
  • 21
  • 1
  • 6

2 Answers2

0
  1. Create objects, which contain the data you posted. Like this:

    public class MyData {
      private String ticket;
      private long saleID;
      // ...
      private List<MyProduct> products;
      // constructor, getters and setters...
    }
    
    public class MyProduct {
      private int menuItemId;
      private int qty;
      // ...
    }
    
  2. when you receive the JSON-Data-String above, you can parse the data into your object with the help of GSON:

    import com.google.gson.Gson;
    
    final String jsonDataString = receive();
    final MyData myData = new Gson().fromJson(jsonDataString, MyData.class);
    
  3. when you collected data in your object and want to send the JSON-Data-String you can also use GSON:

    final MyData myData = collectData();
    final String jsonDataString = new Gson().toJson(myData);
    send(jsonDataString);
    
nyx
  • 477
  • 1
  • 4
  • 10
  • i have to parse this to service. am not get this data from service. – user3789180 Jul 14 '14 at 09:26
  • Sorry, I don't understand you. If you are receiving the data you pasted above, do step 1 and 2, if you have to create the data you pasted above, do step 1 and 3. – nyx Jul 14 '14 at 09:29
0

I would Suggest you to create a setter and getter class having same variable name as in json string you have mentioned above. Also use association(inheritance) in that class. In json content, under each opening and closing curly braces all values resembles a field of java class.

Once the whole setter and getter class is created, set value to each variables using setters. Then create an Object of JSONObject class like.

public class JsonSimpleExample {
 public static void main(String[] args) {

JSONObject obj = new JSONObject();
obj.put("name", "Sample");
obj.put("age", new Integer(100));

JSONArray list = new JSONArray();
list.add("msg 1");
list.add("msg 2");
list.add("msg 3");

obj.put("messages", list);

try {

    FileWriter file = new FileWriter("c:\\test.json");
    file.write(obj.toJSONString());
    file.flush();
    file.close();

} catch (IOException e) {
    e.printStackTrace();
}

System.out.print(obj);

 }

}