Skip to content

Commit

Permalink
hzuapps#6 hzuapps#142 第六次作业改
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleUncle committed Jun 3, 2017
1 parent 096ad76 commit a9f75a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public void onClick(View v) {
this.finish();
startActivity(intent3);
case R.id.send_request://点击按钮从github抓取json文件
Intent intent4=new Intent(Net1414080903135AddObject.this,Net1414080903110_AnalysisJsonActivity.class);
+ startActivity(intent4);
Intent intent4=new Intent(Net1414080903135AddObject.this,Net1414080903135_AnalysisJsonActivity.class);
startActivity(intent4);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import okhttp3.Response;

/*抓取并解析json文件*/
public class Net1414080903110_AnalysisJsonActivity extends AppCompatActivity {
public class Net1414080903135_AnalysisJsonActivity extends AppCompatActivity {
private String grade;
private String name;
private String number;
Expand All @@ -36,7 +36,7 @@ private void sendRequest() {
public void run() {
try {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url("https://raw.githubusercontent.com/hizzj/android-labs-2017/master/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903230/stu_info.json").build();//目标地址
Request request = new Request.Builder().url("https://raw.githubusercontent.com/hizzj/android-labs-2017/master/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903135/stu_info.json").build();//目标地址
Response response = client.newCall(request).execute();
String responseData = response.body().string();
AnalysisJson(responseData);
Expand All @@ -54,9 +54,11 @@ private void AnalysisJson(String jsonData) {
JSONArray jsonArray = new JSONArray(jsonData);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
grade = jsonObject.getString("grade");
name = jsonObject.getString("name");
number = jsonObject.getString("number");
teacher = jsonObject.getString("teacher");
credit = jsonObject.getString("credit");
period = jsonObject.getString("period");
classroom = jsonObject.getString("classroom");
course = jsonObject.getString("course");
}
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -67,7 +69,7 @@ private void AnalysisJson(String jsonData) {
Runnable runnableUi = new Runnable() {
public void run() {
values.put("course",mcourse);
GithubResponse.setText("教师: " + teacher + "\n" + "\n" + ": 学时" + period + "\n" + "\n" + "学分: " + credit+ "\n" + "\n");//显示解析结果
GithubResponse.setText("课程: " + course + "\n" + "教师: " + teacher + "\n" + "\n" +"课室: " + classroom + "\n" + ": 学时" + period + "\n" + "\n" + "学分: " + credit+ "\n" + "\n");//显示解析结果
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"course":"¸ßµÈÊýѧ1","teacher":"·½ÀÏʦ","classroom":"5-222","period":"48¿Îʱ","credit":"3·Ö"}]

0 comments on commit a9f75a0

Please sign in to comment.