【发布时间】:2016-12-17 16:48:25
【问题描述】:
如何在没有json名称的情况下传递JSONArray?
[{
"points": 411,
"type": "C"
}, {
"points": 1600,
"type": "G"
}, {
"points": 13540,
"type": "I"
}]
点显示在 3 个不同的文本视图上,而不是在列表视图上
private class ProgressTask extends AsyncTask<String, Void, Boolean> {
protected void onPreExecute() {
}
protected Boolean doInBackground(final String... args) {
JSONParse jParser = new JSONParse();
HashMap<String, String> hMap = new HashMap<>();
hMap.put("strUserId", "1000000004");
JSONArray jsonarray = jParser.getJSONFromUrl(url,hMap);
// get JSON data from URL
for (int i = 0; i < jsonarray.length(); i++) {
try {
JSONObject c = (JSONObject) jsonarray.get(i);
cpoint=c.getString("points");
gpoint=c.getString("points");
ipoint=c.getString("points");
tpoint = cpoint+gpoint+ipoint;
Log.d("points", String.valueOf(points));
Log.d("type",type);
} catch (JSONException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(final Boolean success) {
txtTotalPoints.setText(tpoint);
txtOwnPoints.setText(ipoint);
txtClubPoints.setText(cpoint);
txtVoucherPoints.setText(gpoint);
}
}
【问题讨论】:
标签: android arrays json android-studio xml-parsing