JAVA阵列输出

时间:2014-03-20 23:39:11

标签: java arrays

您好我试图在JAVA中编写一个JSONArray包装器,它接受String变量date1Str,date2Str和Status并将其包装成下面的格式。我知道这不是json格式,但可以使用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"]
]

1 个答案:

答案 0 :(得分:2)

你想要的是json,只是嵌套数组:

    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));

给出了这个:

[["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"]]