【发布时间】:2020-10-21 03:32:35
【问题描述】:
我需要用 estructure 创建一个 json
{
"label": "any description",
"location":[25.7752965,-100.2636682]
}
带有数组的Json对象,没有键,值(位置),
我试试
String[] _location = new String[2];
_location[0] = String.valueOf(latLng.latitude);
_location[1] = String.valueOf(latLng.longitude);
JSONObject params = new JSONObject();
params.put("location",_location);
params.put("label",_label);
另一个尝试使用:
JsonObject obj = new JsonObject();
JsonArray array_location = new JsonArray();
array_location.add(currentLocation.latitude);
array_location.add(currentLocation.longitude);
JSONObject params = new JSONObject();
params.put("location",_location);
params.put("label",_label);
但是,结果给了我一个带有字符串值的 json...当我需要一个值为 Array double 的键“位置”时
{
"label": "any description",
"location":"[25.7752965,-100.2636682]"
}
【问题讨论】:
标签: android json android-studio android-sdk-tools android-json