【发布时间】:2019-05-14 08:01:07
【问题描述】:
json values in toast type在我的项目中从服务器端获取数据,因为我正在发送带有嵌套数组的数组作为响应。在这张图片中,您可以看到带有数组的“Secondary_number”有一些值。我需要打印这些值。 我附上了我的java代码。当我尝试运行此程序时,我的屏幕变黑了。
JSONObject obj = new JSONObject(response);
JSONArray jsonArray = obj.getJSONArray("response");
service = new String[jsonArray.length()];
//Iterate the jsonArray and print the info of JSONObjects
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i)
//getting second array
JSONArray jArray = jsonObject.getJSONArray("secondary_number");
//Iterate the jsonArray and print the info of JSONObjects
for (int j = 0; j < jArray.length(); j++) {
do some computation
}
service[i] = jsonObject.getString("service_id").toString(); //getting values in response
tv1 = jsonObject.getString("service_id");
tv2 = jsonObject.getString("user_id").toString();
tv3 = jsonObject.getString("username").toString();
tv4 = jsonObject.getString("company_name").toString();
tv5 = jsonObject.getString("assigned_time").toString();
请帮帮忙
【问题讨论】:
-
开始修正标题,让它变得有意义。 “请帮助”不是:这一切都是为了获得帮助。
-
请正确格式化代码...