-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #470 from 1414080903124/master
- Loading branch information
Showing
6 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...java/edu/hzuapps/androidlabs/homeworks/net1414080903124/Net1414080903124AnalysisJson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package edu.hzuapps.androidlabs.homeworks.net1414080903124; | ||
|
||
import android.os.Handler; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.widget.TextView; | ||
|
||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import edu.hzuapps.androidlabs.R; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
; | ||
|
||
public class Net1414080903124AnalysisJson extends AppCompatActivity { | ||
private String soft_name; | ||
private String developer; | ||
private String version; | ||
private TextView GithubResponse; | ||
private Handler handler = null; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_net1414080903124_analysis_json); | ||
handler = new Handler(); | ||
GithubResponse = (TextView) findViewById(R.id.analysis_json); | ||
Request(); | ||
} | ||
private void Request() { | ||
new Thread(){ | ||
@Override | ||
public void run() { | ||
try { | ||
OkHttpClient client = new OkHttpClient(); | ||
Request request = new Request.Builder().url("https://raw.githubusercontent.com/1414080903124/android-labs-2017/master/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903124/Net141408093116SoftInfo.json").build();//目标地址 | ||
Response response = client.newCall(request).execute(); | ||
String responseData = response.body().string(); | ||
Analysis(responseData); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
handler.post(runnableUi); | ||
} | ||
}.start(); | ||
} | ||
/*解析json文件*/ | ||
private void Analysis(String jsonData) { | ||
try { | ||
JSONArray jsonArray = new JSONArray(jsonData); | ||
for (int i = 0; i < jsonArray.length(); i++) { | ||
JSONObject jsonObject = jsonArray.getJSONObject(i); | ||
soft_name= jsonObject.getString("soft_name"); | ||
developer= jsonObject.getString("developer"); | ||
version = jsonObject.getString("version"); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
/*更新UI*/ | ||
Runnable runnableUi = new Runnable() { | ||
public void run() { | ||
GithubResponse.setText("软件名: " + soft_name + "\n" + "\n" + "开发者: " + developer + "\n" + "\n" + "版本号: " + version + "\n" + "\n");//显示解析结果 | ||
} | ||
}; | ||
} |
1 change: 1 addition & 0 deletions
1
...main/java/edu/hzuapps/androidlabs/homeworks/net1414080903124/Net141408093116SoftInfo.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"soft_name":"WALLET","developer":"WBQ","version":"1.0"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
AndroidLabs/app/src/main/res/layout/activity_net1414080903124_analysis_json.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/activity_net1414080903124_analysis_json" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
tools:context="edu.hzuapps.androidlabs.homeworks.net1414080903124.Net1414080903124AnalysisJson"> | ||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:id="@+id/analysis_json"/> | ||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters