【发布时间】:2016-07-11 12:35:07
【问题描述】:
我在 Android 23 上尝试了一个应用程序,但我卡在了某个地方。
我有一个请求,但它不是 URL 格式!!!!它的字符串格式。我在服务器上发布并返回数据。
例如我的网址是=http://api.someurl/app_dev.php/tr/content
我需要发布一些字符串参数,例如
{
"command":"read",
"ctrl":"summaryOfDay",
"data":{"date":"08.04.2016"},
"order":null,
"limit":null
}
它应该返回一些 json 数据。因为这个请求是搜索参数!
我的代码是
HttpURLConnection connection=null;
BufferedReader reader=null;
try {
URL url=new URL(params[0]);
connection=(HttpURLConnection)url.openConnection();
InputStream stream=connection.getInputStream();
reader=new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer=new StringBuffer();
String line = "";
while ((line = reader.readLine())!= null){
buffer.append(line);
}
String sJson = buffer.toString();
JSONObject mjson = new JSONObject(sJson);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
那么我怎样才能发布这些字符串并获取我的 json 日期。
问候。
【问题讨论】:
-
你应该使用第三方,比如'Retrofit'或'Volley' :)
-
我相信这回答了你的问题:stackoverflow.com/questions/4205980/….
-
你需要解析JsonObject吗? stackoverflow.com/questions/2591098/how-to-parse-json-in-java 或您的 JSON 字符串响应不正确。究竟是什么问题?
-
我需要发送参数并获取json数据@cricket_007
标签: android json web-services