所以我想从一个看起来像这样的网站解析 Json 文件:
{ “tnum”:“12805”,“tname”:“JANMABHOOMI EXP”,“tdate”:“25-2-2013”,“from”:“GNT”,“to”:“SC”,“class”: "CC", "charted": true, "numofpax": 2, "pax": [{ "coach": "D2", "berth": "23", "quota": "GN", "status": “CNF”},{“教练”:“S2”,“泊位”:“43”,“配额”:“GN”,“状态”:“CNF”}]}
这是我写的不完整的代码:
EditText num = (EditText)findViewById(R.id.pnr_num);
String numPNR= num.getText().toString();
url = "http://www.railpnrapi.com/";
url = url.concat(numPNR);
TextView t = (TextView)findViewById(R.id.textView1);
t.setText(url);
JSONObject jsonObj = null;
try {
jsonObj = new JSONObject(url);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// grabbing the menu object
try {
String id = jsonObj.getString("tname");
TextView t1 = (TextView)findViewById(R.id.textView1);
t1.setText(id);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但是,每次我的应用程序崩溃时。我什至添加了网络访问权限!
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
我在哪里做错了?谢谢。PS这里是我尝试使用示例输入访问的站点: