英文:
how to make this json object in android java
问题
这是我的代码:
{
"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 API Gateway。请帮助我在Android Studio的Java中创建这个对象。谢谢。
英文:
Here is my code:
{
"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]]}"
}
I want to send above json to aws apigateway via POST request. Please help me to make this object in android studio java.
Thanks.
答案1
得分: -1
尝试一下:
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();
}
英文:
Try this:
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();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论