【发布时间】:2020-02-05 21:38:47
【问题描述】:
我有这行代码,我想从“列表”中删除数字。哪一种是实现它的好方法?我是开发新手,这是我被困了好几天的地方。
protected Void doInBackground(Void... voids) {
try {
URL url = new URL("https://{myUrl}");
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
while (line != null){
line = bufferedReader.readLine();
data = data + line; }
JSONArray JA = new JSONArray(data);
for (int i = 0; i <JA.length(); i++ ){
JSONObject JO = (JSONObject) JA.get(i);
singleParsed = "list:" + JO.get("list");
dataParsed = dataParsed + singleParsed;
} } catch (MalformedURLException e) {
e.printStackTrace(); } catch (IOException e) {
e.printStackTrace(); } catch (JSONException e) {
e.printStackTrace(); }
return null; }
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
MainActivity.data.setText(this.dataParsed);
} ```
JSON file
{
"common":{
"mixed":"yes",
"nums":{
"list":[
1,
2,
3,
4
],
"other":[
5
]
}}
}
【问题讨论】:
-
您没有正确使用 HttpURLConnection,您的 API url 方法是什么?获取还是发布?
标签: java android json android-studio