android之线程访问网络并解析数据

public void getData()

{

new Thread()

{

public void run()

{

HttpServer httpServer = new HttpServer(getActivity(), mHandler);

HttpURLConnection conn = httpServer

.getHttpService("http://bbs.pinggu.org/appapi.php?ac=viewthread&tid="

+ getShownUrl());

if (conn != null)

{

java.io.BufferedReader bReader;

try

{

bReader = new java.io.BufferedReader(

new java.io.InputStreamReader(

conn.getInputStream()));

String result = bReader.readLine().toString().trim();

System.out.println("获取数据:" + result);

if (result != null)

{

//解析数据

JSONObject resultObject = new JSONObject(result);

String statusString = resultObject

.getString("status");

if (statusString.equals("1"))

{


}

}

}

catch (JSONException e)

{

// TODO Auto-generated catch block

e.printStackTrace();

}

catch (IOException e)

{

// TODO Auto-generated catch block

e.printStackTrace();

}


}

}

}.start();

}


你可能感兴趣的:(android,网络,null,public,result)