I have the following json string I want to convert to java code so I can alter it easier and send the newer request but I cannot seem to figure out how to generate it with JSONObject and JSONArray.
["guest_login",{"chips":{"1":2000},"epoch":1552509677,"invested":{"1":2000},"login_id":10,"news":["Welcome to Poker.","Register and get started with 2000 play chips."],"username":"Guest10"}]
I get the following output
output = ["guest_login",null,null]
Here is what I tried so far.
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
JSONObject obj = new JSONObject();
JSONArray list = new JSONArray();
list.add("guest_login");
list.add(new JSONObject().put("chips", new JSONObject().put("1", "2000")));
list.add(obj.put("epoch", "1552509677"));
System.out.println("output = " + list.toString());
also tried
JSONObject json = new JSONObject();
json.put("name", "student");
JSONArray array = new JSONArray();
JSONObject item = new JSONObject();
item.put("invested", new JSONObject().put("1", "2000"));
item.put("login_id", "10");
item.put("epoch", "1552509677");
item.put("chips", new JSONObject().put("1", "2000"));
item.put("news", new JSONArray().add("Welcome to Poker.").add("Register and get started with 2000 play chips."));
item.put("username","Guest10");
json.put("guest_login", new JSONArray().add(item));
message = json.toString();
System.out.println("output = " + message);