Android 实现json网络数据通过BaseAdapter加载到ListView中

本文展示了如何在Android应用中从自建服务器获取JSON数据,并通过BaseAdapter将这些数据加载到ListView中。作者提供了PHP服务器端代码、AndroidManifest.xml配置、各主要Java类(如MainActivity和JsonAdapter)的概览,实现了数据的解析和显示。尽管界面设计简单,但整个过程详细介绍了实现步骤。
摘要由CSDN通过智能技术生成

效果图,有点没有设计美感,哈哈,凑合着看吧

这里写图片描述

关于json,我对json有一定的了解,所以这个项目我用自己构建的服务器输出json数据,文件名json.php
php代码如下

<?php 
$json="{'data':1,'students':[{
   'name':'张三','age':22,'url':'http://192.168.1.103/pictures/pic1.jpg'},{
   'name':'李四','age':23,'url':'http://192.168.1.103/pictures/pic2.jpg'},{
   'name':'王五','age':26,'url':'http://192.168.1.103/pictures/pic3.jpg'},{
   'name':'刘流','age':32,'url':'http://192.168.1.103/pictures/pic4.jpg'},{
   'name':'陈曦','age':22,'url':'http://192.168.1.103/pictures/pic5.jpg'}]}"; 
echo $json; 
?>

Android文件目录图:

这里写图片描述

Android配置页AndroidMenifests.xml代码如下

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.imooc.capton.json">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://s
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值