不能打印出json格式的数据
package com.example.administrator.imooclist;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends Activity {
private ListView listView;
private static String URL = "http://www.imooc.com/api/teacher?type=4&num=30";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.ListView);
new newAsyncTask().execute(URL);
}
private List<newBean> getJsonData(String url) {
List<newBean> listNewBean = new ArrayList<>();
try {
String jsonString = readInputStream(new URL(url).openStream());
Log.i("EE",jsonString);
} catch (IOException e) {
e.printStackTrace();
}
return listNewBean;
}
//数据的读取,把json格式的数据转化为我们需要的数据
private String readInputStream (InputStream inputStream){//InputStream字节流
InputStreamReader inputStreamReader ;
String result = "";
try {
String line ="";
inputStreamReader = new InputStreamReader(inputStream,"utf-8");//讲字节流转化为字符流
//通过BuffereReader将字符流以buffere的形式读出来
BufferedReader buffereReader = new BufferedReader(inputStreamReader);
while ((line = buffereReader.readLine())!=null){//读取的字符流拼接到result中 连成字符串
result+=line;
}
inputStream.close();
inputStreamReader.close();
buffereReader.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
class newAsyncTask extends AsyncTask<String,Void,List<newBean>>{
@Override
protected List<newBean> doInBackground(String... params) {
return getJsonData(params[0]);
}
}
}
以上是我的代码,求解答