JSON数据能解析,但不能完全显示 JsonParse.getListPerson 也不知道咋实现的,可能出现的问题,比如中文处理不好,用全英文试试。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 整个Json类public class JsonParse { /** * 解析Json数据 * * @param urlPath * @return mlists * @throws Exception */ public static List<Person> getListPerson(String urlPath) throws Exception { List<Person> mlists = new ArrayList<Person>(); byte[] data = readParse(urlPath); JSONArray array = new JSONArray(new String(data)); for (int i = 0; i < array.length(); i++) { JSONObject item = array.getJSONObject(i); String name = item.getString("name"); String address = item.getString("address"); int age = item.getInt("age"); mlists.add(new Person(name, address, age)); } return mlists; } /** * 从指定的url中获取字节数组 * * @param urlPath * @return 字节数组 * @throws Exception */ public static byte[] readParse(String urlPath) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] data = new byte[1024]; int len = 0; URL url = new URL(urlPath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream inStream = conn.getInputStream(); while ((len = inStream.read(data)) != -1) { outStream.write(data, 0, len); } inStream.close(); return outStream.toByteArray(); }}还有就是JSON里面都是英文 用 JSONArrary jarr = new JSONArrary("[ {"id":"01","name":"张三","国籍":“中国”}]"); 试试? JSONArray array = new JSONArray(new String(data));获取的是正确的json格式,或者是你预期的格式吗? 这种你要自己写一个adapter,就可以了 不是应该通过jsonarray解析吗? 如何判断dialog获得焦点和失去焦点? 一个按钮上的文字不居中显示的问题 如何在 google map上标记当前位置并保存为图片格式保存下来? 如何启动系统自带的camera程序 安卓webview加载的网页如何放大 关于自定义EditText,求助! 有没有可用于Android平台二次开发的CAD控件? 请问这种布局要怎么实现 android初学者求助大牛 一个android项目工程的源程序中,定义了一个变量 mManager;它是从何而来? 新人HelloAndroid onCreate 空指针错误 请教能否实现fragment内操控其fragmentActivity
整个Json类public class JsonParse { /** * 解析Json数据 * * @param urlPath * @return mlists * @throws Exception */ public static List<Person> getListPerson(String urlPath) throws Exception { List<Person> mlists = new ArrayList<Person>(); byte[] data = readParse(urlPath); JSONArray array = new JSONArray(new String(data)); for (int i = 0; i < array.length(); i++) { JSONObject item = array.getJSONObject(i); String name = item.getString("name"); String address = item.getString("address"); int age = item.getInt("age"); mlists.add(new Person(name, address, age)); } return mlists; } /** * 从指定的url中获取字节数组 * * @param urlPath * @return 字节数组 * @throws Exception */ public static byte[] readParse(String urlPath) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] data = new byte[1024]; int len = 0; URL url = new URL(urlPath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream inStream = conn.getInputStream(); while ((len = inStream.read(data)) != -1) { outStream.write(data, 0, len); } inStream.close(); return outStream.toByteArray(); }}还有就是JSON里面都是英文