我需要形成一个像这样的 JSON 对象。
{
"GroupID": 24536,
"Section": [1,2,3,4,5]
}
这是我尝试过的,但是当我查看对象结构时,节数组没有正确形成。
JSONObject Object = new JSONObject();
Object.put("Group", GroupID);
int[] section = {1,2,3,4,5};
Object.put("Section", section);
最佳答案
尝试:
JSONObject Object = new JSONObject();
Object.put("Group", GroupID);
Integer[] section = {1,2,3,4,5};
Object.put("Section", new JSONArray(Arrays.asList(section)));
关于java - 在 android 中创建 JSONObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15960245/