## app_java [点击下载](http://oez9hnxxu.bkt.clouddn.com/files/app_java.apk) 扫码下载 ![](https://box.kancloud.cn/eda4f20427afd5faed5667ca7a2b4fda_264x268.png) ### 逻辑截图 ![](https://box.kancloud.cn/9ffcda41df9a56b6e7cfccca4673d318_694x587.png) ![](https://box.kancloud.cn/6e5bb1e65a30d87dce83352649edfef2_1106x757.png) ### 逻辑代码 ~~~ package com.example.app_java; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.xutils.x; import org.xutils.common.Callback.CommonCallback; import org.xutils.http.RequestParams; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends ActionBarActivity { private EditText et_key;//关键词 private Button btn_search;//查询按钮 private TextView tv_name;//姓名 private TextView tv_num;//学号 private TextView tv_classs;//班级 private TextView tv_nation;//名族 private TextView tv_addr;//地址 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); x.Ext.init(getApplication()); x.Ext.setDebug(true); // 是否输出debug日志 //初始化控件 initElem(); initClick(); } private void initElem() { //关键词 et_key=(EditText) findViewById(R.id.et_key); //查询按钮 btn_search=(Button) findViewById(R.id.btn_search); tv_name=(TextView) findViewById(R.id.tv_name); tv_num=(TextView) findViewById(R.id.tv_num); tv_classs=(TextView) findViewById(R.id.tv_classs); tv_nation=(TextView) findViewById(R.id.tv_nation); tv_addr=(TextView) findViewById(R.id.tv_addr); } private void initClick(){ btn_search.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { RequestParams params = new RequestParams("http://node.lintul.com/info/getpage"); params.addParameter("pi",1); params.addParameter("ps",1); params.addParameter("key",et_key.getText().toString()); x.http().post(params, new CommonCallback<String>() { @Override public void onError(Throwable arg0, boolean arg1) { Toast.makeText(MainActivity.this, "抱歉出错了", Toast.LENGTH_LONG).show(); } @Override public void onSuccess(String arg0) { try { JSONObject JsonData = new JSONObject(arg0); int status = JsonData.getInt("status"); if (status==2) { JSONObject message = JsonData.getJSONObject("message"); JSONArray dataArray=message.getJSONArray("data"); JSONObject oneInfo=dataArray.getJSONObject(0); tv_num.setText(oneInfo.getString("num")); tv_name.setText(oneInfo.getString("name")); tv_classs.setText(oneInfo.getString("classs")); tv_nation.setText(oneInfo.getString("nation")); tv_addr.setText(oneInfo.getString("address")); Toast.makeText(MainActivity.this, "查询到:"+oneInfo.getString("name"), Toast.LENGTH_LONG).show(); }else { Toast.makeText(MainActivity.this, "未查询到数据", Toast.LENGTH_LONG).show(); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onCancelled(CancelledException arg0) {} @Override public void onFinished() {} }); } }); } } ~~~ ### 视图截图 ![](https://box.kancloud.cn/5e5ba8a0d2461865b0bf51022c5ef9d8_287x469.png) ### 视图代码 ~~~ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" 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="com.example.app_java.MainActivity" > <LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <EditText android:id="@+id/et_key" android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="姓名" android:ems="10" android:inputType="textNoSuggestions" /> <requestFocus android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/btn_search" android:layout_width="88dp" android:layout_height="wrap_content" android:layout_marginRight="24dp" android:text="@string/search" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_weight="3.95" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="学号:" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/tv_num" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="。。。" android:textAppearance="?android:attr/textAppearanceSmall" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_weight="3.95" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="姓名:" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/tv_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="。。。" android:textAppearance="?android:attr/textAppearanceSmall" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_weight="3.95" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="班级:" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/tv_classs" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="。。。" android:textAppearance="?android:attr/textAppearanceSmall" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_weight="3.95" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="名族:" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/tv_nation" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="。。。" android:textAppearance="?android:attr/textAppearanceSmall" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginTop="20dp" android:layout_weight="0.81" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="地址:" android:textAppearance="?android:attr/textAppearanceMedium" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="27.68" > <TextView android:id="@+id/tv_addr" android:layout_width="wrap_content" android:layout_height="158dp" android:layout_weight="0.81" android:text="..." android:textAppearance="?android:attr/textAppearanceMedium" /> </LinearLayout> </LinearLayout> </RelativeLayout> ~~~ ## pc 效果图 ![](https://box.kancloud.cn/8f2c54a1f9162934c10ee8224b91a6bb_290x316.png) 代码 ~~~ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; using System.IO; using Newtonsoft.Json; namespace pc_.net { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btn_search_Click(object sender, EventArgs e) { // MessageBox.Show("hello"); string key = tb_key.Text.Trim(); string jsonRes = Post_Http("http://node.lintul.com/info/getpage", "pi=1&ps=2&key="+key); try { Messages res = JsonConvert.DeserializeObject<Messages>(jsonRes); if (res.status == 2) { tb_name.Text = res.message.data[0].name; tb_num.Text = res.message.data[0].num; tb_classs.Text = res.message.data[0].classs; tb_nation.Text = res.message.data[0].nation; tb_addr.Text = res.message.data[0].address; } else { MessageBox.Show("未查询到数据"); } } catch (Exception ex) { ex.ToString(); MessageBox.Show("未查询到数据"); } // JsonObject } public static string Post_Http(string url, string postData) { string strResult = null; try { Encoding encoding = Encoding.GetEncoding("utf-8"); byte[] POST = encoding.GetBytes(postData); HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); myRequest.Method = "POST"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.ContentLength = POST.Length; Stream newStream = myRequest.GetRequestStream(); newStream.Write(POST, 0, POST.Length); //设置POST newStream.Close(); // 获取结果数据 HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); strResult = reader.ReadToEnd(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return strResult; } } public class Messages { public int status { get; set; } public Item message { get; set; } } public class Item { public int count { get; set; } public OneInfo[] data { get; set; } } public class OneInfo { public int id { get; set; } public string name { get; set; } public string num { get; set; } public string sex { get; set; } public string classs { get; set; } public string nation { get; set; } public string address { get; set; } } } ~~~ 代码截图 ![](https://box.kancloud.cn/6a0907a313b233d1d674d85a5857d483_776x374.png) ![](https://box.kancloud.cn/739c605bcca26a63f596068080ad880b_732x408.png) ## ionic ionic start app_js --v2 ionic platform add android ~~~ D:\demo\App>ionic start app_js --v2 Creating Ionic app in folder D:\demo\App\app_js based on tabs project Downloading: https://github.com/driftyco/ionic2-app-base/archive/master.zip [=============================] 100% 0.0s Downloading: https://github.com/driftyco/ionic2-starter-tabs/archive/master.zip [=============================] 100% 0.0s Installing npm packages... Adding initial native plugins [=============================] 100% 0.0s Saving your Ionic app state of platforms and plugins Saved platform Saved plugins Saved package.json ♬ ♫ ♬ ♫ Your Ionic app is ready to go! ♬ ♫ ♬ ♫ Some helpful tips: Run your app in the browser (great for initial development): ionic serve Run on a device or simulator: ionic run ios[android,browser] Test and share your app on device with Ionic View: http://view.ionic.io Build better Enterprise apps with expert Ionic support: http://ionic.io/enterprise Create an Ionic Cloud account to add features like User Authentication, Push Notifications, Live Updating, iOS builds, and more? (Y/n): n New to Ionic? Get started here: http://ionicframework.com/docs/v2/getting-started D:\demo\App>ionic serve Couldn't find ionic.config.json file. Are you in an Ionic project? D:\demo\App>cd app_js D:\demo\App\app_js>ionic serve Running 'serve:before' npm script before serve ~~~ ![](https://box.kancloud.cn/7ef59f958c94cfa9aa8726605b2dd3b7_734x681.png) ![](https://box.kancloud.cn/b13982a16b4aad49b9812d07046e2bed_462x679.png)