java - 在 android 中创建 JSONObject

标签 java android

我需要形成一个像这样的 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/

相关文章:

java - 在Spring中,我们将如何保证操作的原子性

android - 为 Robolectric 测试导入正确的 AssertThat 方法

android - 不幸的是,应用程序在使用 fragment build设置时已停止

android - 如何在 Android 中为整个应用程序设置自定义字体?

Java Servlet 发布请求不适用于 ServletFileUpload

java - 为什么 hashcode() 返回一个整数而不是长?

javascript - Android WebView 中不显示 Twitter 视频

android - 如何在android中的 TextView 中添加动画

java - android中两个矩形之间的碰撞检测

java - AsyncExecutor 看起来不是异步的