java - JSONException: courseDivide 没有值
问题描述
刚尝试运行,我收到此错误:
JSONException: courseDivide StatisticsFragment$ByEntire.onPostExecute(StatisticsFragment.java:225) StatisticsFragment$ByEntire.onPostExecute(StatisticsFragment.java:153) 没有值
我是 Java 的初学者,我似乎无法弄清楚为什么 JSONException 没有价值。
编码:
class ByEntire extends AsyncTask<Void, Void, String> {
String target;
ProgressDialog dialog = new ProgressDialog(getActivity());
@Override
protected void onPreExecute(){
try{
target = "http://wook1150.cafe24.com/ByEntire.php";
dialog.setMessage("로딩중");
dialog.show();
}
catch (Exception e)
{
e.printStackTrace();
}
}
@Override
protected String doInBackground(Void... voids) {
try {
URL url = new URL(target);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String temp;
StringBuilder stringBuilder = new StringBuilder();
while ((temp = bufferedReader.readLine()) !=null)
{
stringBuilder.append(temp + "\n");
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return stringBuilder.toString().trim();
} catch (Exception e)
{
e.printStackTrace();
}
return null;
}
@Override
public void onProgressUpdate(Void... values){
super.onProgressUpdate();
}
@Override
public void onPostExecute(String result){
try{
JSONObject jsonObject = new JSONObject(result);
JSONArray jsonArray = jsonObject.getJSONArray("response");
int count = 0;
int courseID;
String courseGrade;
String courseTitle;
String courseProfessor;
int courseCredit;
int courseDivide; //////Error here//////
int coursePersonnel;
String courseTime;
while(count < jsonArray.length()){
JSONObject object = jsonArray.getJSONObject(count);
courseID = object.getInt("courseID");
courseGrade = object.getString("courseGrade");
courseTitle = object.getString("courseTitle");
courseProfessor = object.getString("courseProfessor");
courseCredit = object.getInt("courseCredit");
courseDivide = object.getInt("courseDivide)");
coursePersonnel = object.getInt("coursePersonnel)");
courseTime = object.getString("courseTime)");
rankList.add(new Course(courseID, courseGrade, courseTitle, courseCredit, courseDivide, coursePersonnel,courseTime, courseProfessor));
count++;
dialog.dismiss();
}
rankListAdapter.notifyDataSetChanged();
}catch (Exception e){
e.printStackTrace();
}
}
}
解决方案
可能是您的 JSON 没有 courseDivide 或输入错误,删除 ')'
courseDivide = object.getInt("courseDivide");
coursePersonnel = object.getInt("coursePersonnel");
courseTime = object.getString("courseTime");
推荐阅读
- flutter - 如何从java代码中获取数据到flutter
- r - 减少 R 包的检查时间
- c - 我如何只允许 C 中的整数?
- flutter - 按下按钮时具有动态高度的 BottomSheet (DraggableScrollableSheet)
- apache-spark - Spark 单元测试:使用在内存数据库上运行的 HiveMetaStore 启动 spark 会话
- javascript - 在删除记录之前使用 javascript 自定义对话框。但不知道如何通过js发送php值
- typescript - “??” TypeScript 中的运算符
- javascript - 在 for 循环中处理 then-able Java-script 函数以填充数组
- php - php在MYSQL数据库中插入多行
- javascript - 添加指向动态 div 元素的链接只能通过背景图像区分