我是 android 世界的新手,我正在尝试从以下 URL 检索 JSONArray:http: //www.softmarketing.it/json/view/azienda/7
TabHostExample.java:
public class TabHostExample extends TabActivity {
private static String url = "http://www.softmarketing.it/json/view/azienda/7";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab_host_example);
//JSONParser parser= new JSONParser();
//JSONObject myJSON= parser.makeHttpRequest(url, "POST", null);
try{
// Create a new HTTP Client
DefaultHttpClient defaultClient = new DefaultHttpClient();
// Setup the get request
HttpGet httpGetRequest = new HttpGet("http://www.softmarketing.it/json/view/azienda/7");
// Execute the request in the client
HttpResponse httpResponse = defaultClient.execute(httpGetRequest);
// Grab the response
BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
String json = reader.readLine();
// Instantiate a JSON object from the request response
JSONObject jsonObject = new JSONObject(json);
} catch(Exception e){
// In your production code handle any errors and catch the individual exceptions
e.printStackTrace();
}
.....
在 LogCat 我看到这个:
12-16 08:14:41.987: E/MYAPP(1183): exception: null
12-16 08:21:34.927: E/MYAPP(1245): exception: null
并且变量 e 具有以下值:
e:原因:NetworkOnMainThreadEception
和其他价值观...
请问你能帮帮我吗?我试图解决解析已经三天了......谢谢