【发布时间】:2016-11-18 00:29:40
【问题描述】:
我正在用 java 制作一个小应用程序。我正在尝试返回 JSON 数组。但我遇到了错误,我需要使用我存储的 cookie,将其拆分并作为 JSON 数组返回。
String json = null;
if(json == null)
{
//return empty array
json = "[]";
}
else
{
//split cookie
String wl[] = wishList.split("~");
json += "[";
for(int i = 0; i < json.length(); ++i)
{
json += wl[i];
}
json += "]";
问题是我不确定这是否是返回 json 数组的正确方法, 任何帮助都会很棒。谢谢!
【问题讨论】:
-
你遇到了什么错误?
-
我想你的意思是
i < wl.length。此外,您需要转义、引用和逗号分隔标记。如果你使用像 jackson 这样的库会容易得多。