我的代码看起来像这样:
import net.sf.json.*;--just so you know what the library is
...
JSONArray a = new JSONArray();
JSONObject p = new JSONObject();
p.put("some_attribute1","some normal string");
p.put("some_attribute2","[3something]");
p.put("some_attribute3","[something3]");
a.add(p);
System.out.println(a.toString());
这会产生:
[
{
"some_attribute1":"some normal string",
"some_attribute2":["3something"],
"some_attribute3":"[something3]"
}
]
而不是期望的结果:
[
{
"some_attribute1":"some normal string",
"some_attribute2":"[3something]",
"some_attribute3":"[something3]"
}
]
请注意“some_attribute2”作为实际输出中的数组与所需输出中的字符串之间的区别。谁能解释这是为什么?另外,如果有一个术语可以更好地对我的问题进行分类?