簡體   English   中英

如何以這種格式發送json請求

[英]How to send json request in this format

我想以這種格式發送json請求

"coordinates":{"0":{"received_at":1471529314,"lat":28.6888798,"long":77.3247225}}

但我能夠以這種格式發送請求

{"coordinates":{"0":{"received_at":1471529314,"lat":28.6888798,"long":77.3247225}}}

我正在使用此代碼

            jsonObject.put("received_at", now);
            jsonObject.put("lat", latitude);
            jsonObject.put("long", longitude);
            JSONObject json = new JSONObject();
            json.put("0",jsonObject);
            jsonObject1 = new JSONObject();
            jsonObject1.put("coordinates",json);
            Log.e("JSON",jsonObject1.toString());

您共享的第一個請求不是有效的JSON。 JSON字符串必須始終以{表示JSONObject或以[表示JSONArray。
如果您堅持使用第一種格式,那么我認為您必須自己構建該字符串

要刪除第一個和最后一個括號,請使用此

String specialString = jsonObject1.toString().substring(1, jsonObject1.toString().length() - 1);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM