【发布时间】:2015-04-22 11:40:16
【问题描述】:
我有由 Gson 库创建的 JSON 字符串,我想使用 HttpURLConnection API“GET”将此字符串发送到 localhost 服务器(wamp)。我将在通过 USB 电缆与笔记本电脑连接的 S4 设备上运行该应用程序。
感谢您的帮助。
我有这个 JSON 字符串:
{
"latitude":80.86907321,
"longitude":15.66542435,
"formatted":"22.04.2015 11:11:00",
"route":4
}
我在内部类“MyLocationListener”中有这个方法:
private String convertToJSON(double pLong, double pLat, String formatted) {
//envelop the data in JSON format.
Data d = new Data(pLat, pLong, formatted,route_number);
Gson gson = new GsonBuilder().registerTypeAdapter(Data.class, new DataSerializer()).create();
return gson.toJson(d);
}
【问题讨论】:
-
你的问题到底是什么?
-
@Sidd:如何使用 HttpURLConnection api 将此 JSON 字符串发送到我的本地主机?我将在我的设备上测试该应用程序。