java - 如何在android java中制作这个json对象
问题描述
这是我的代码:
{
"body": "{\"data\": [[1633209578,0,117.000000],[1633209578,1,116.000000],[1633209624,2,121.000000],[1633209643,3,174.000000],[1633209682,4,222.000000],[1633209715,5,247.000000],[1633209748,6,248.000000],[1633209781,7,248.000000],[1633209814,8,249.000000],[1633209847,9,248.000000],[1633209877,10,248.000000],[1633209912,11,248.000000],[1633209943,12,248.000000],[1633209990,13,248.000000],[1633210009,14,248.000000]]}"
}
我想通过 POST 请求将上面的 json 发送到 aws apigateway。请帮我在 android studio java 中制作这个对象。谢谢。
解决方案
尝试这个:
String[] value=new String[]{"[1633209578, 0, 117.000000]",
"[1633209578, 1, 116.000000]",
"[1633209624, 2, 121.000000]",
"[1633209643, 3, 174.000000]",
"[1633209682, 4, 222.000000]",
"[1633209715, 5, 247.000000]",
"[1633209748, 6, 248.000000]",
"[1633209781, 7, 248.000000]",
"[1633209814, 8, 249.000000]",
"[1633209847, 9, 248.000000]",
"[1633209877, 10, 248.000000]",
"[1633209912, 11, 248.000000]",
"[1633209943, 12, 248.000000]",
"[1633209990, 13, 248.000000]",
"[1633210009, 14, 248.000000]"};
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < value.length; i++) {
jsonArray.put(value[i]);
}
JSONObject jsonObject=new JSONObject();
try {
jsonObject.put("data",jsonArray);
JSONObject object=new JSONObject();
object.put("body",jsonObject);
Log.i("FinalJson",object.toString());
} catch (JSONException e) {
e.printStackTrace();
}
推荐阅读
- java - Android libgdx:按下启动器图标后启动画面未立即显示
- java - 带有 Confluent 的 Spring Cloud Stream Kafka 不会产生与带有 Confluent 的 Spring Kafka 相同的消息
- python - 控制台不导出任何抓取的数据
- jodd - jre 7 支持哪个版本的 jodd-http?
- c# - 带有数据绑定的 LiveCharts 派生的用户控件不显示图表
- mysql - 使用外键从多表中删除数据
- angular - 从动态生成的表中过滤记录以进行角度更新
- firebase - 向 Firebase 规则添加管理员权限
- ios - CoreStore 在上下文中创建对象而不保存到数据库
- spring-boot - 如何将异步数据写入远程端点而不会出现“未找到合适的写入器异常”?