2

Hi I'm trying to write a JSONArray wrapper in JAVA that takes String variables date1Str, date2Str, and Status and wraps it into the format below. I know this is not a json format but is it possible to pass something like this using REST Client?

[
   ["2014-03-20T11:23:25.000-07:00","2014-03-20T11:23:25.000-07:00","Open"],
   ["2014-03-19T22:06:01.000-07:00","2014-03-19T22:06:01.000-07:00","Open"],
   ["2014-03-19T21:05:08.000-07:00","2014-03-19T21:05:34.000-07:00","In Progress"],
   ["2014-03-19T21:04:49.000-07:00","2014-03-19T21:14:56.000-07:00","Closed"]
]
2
  • You should be able to take your original array containing the items and put them into another array and then hand the parent array to a JSON Serializer and it should output what you want.... Commented Mar 20, 2014 at 23:44
  • If you want to serve a restful client, you need to return JSON. Check out jersey.java.net - they do what you want. Commented Mar 20, 2014 at 23:46

1 Answer 1

2

What you want is json, just nested arrays:

    String[] foo = {"2014-03-20T11:23:25.000-07:00", "2014-03-20T11:23:25.000-07:00", "Open"};
    String[] bar = {"2014-03-19T22:06:01.000-07:00", "2014-03-19T22:06:01.000-07:00", "Open"};
    String[] baz = {"2014-03-19T21:05:08.000-07:00","2014-03-19T21:05:34.000-07:00","In Progress"};
    String[] fum = {"2014-03-19T21:04:49.000-07:00","2014-03-19T21:14:56.000-07:00","Closed"};

    String[][] fnord = {foo, bar, baz, fum};

    System.out.println(new Gson().toJson(fnord));

gives this:

[["2014-03-20T11:23:25.000-07:00","2014-03-20T11:23:25.000-07:00","Open"],["2014-03-19T22:06:01.000-07:00","2014-03-19T22:06:01.000-07:00","Open"],["2014-03-19T21:05:08.000-07:00","2014-03-19T21:05:34.000-07:00","In Progress"],["2014-03-19T21:04:49.000-07:00","2014-03-19T21:14:56.000-07:00","Closed"]]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I'm using simple JSONArray, and used your example and did this: obj.add(Arrays.asList(new String []{"2014-03-20T11:23:25.000-07:00","2014-03-20T11:23:25.000-07:00","Open"})); Thanks again :) -azurefrog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.