【发布时间】:2011-04-21 13:46:25
【问题描述】:
我已经构建了一个 java 服务器应用程序,并试图让我的 android 应用程序与之通信。阅读Android Client Server communication 后,我尝试了套接字示例。但是我碰壁了,因为在服务器端我可以返回一个对象数组,但在客户端我无法检索它,因为 buffereader 只接受一个字符串 服务器代码
public List<Person> processInput(String theInput) {
String peopleOutput = null;
List<Person> people = new ArrayList<Person>();
if (state == WAITING) {
SqliteDBhelper db = new SqliteDBhelper();
people = db.getPeople();
return people;
客户端代码
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
List<Person> fromServer;
String fromUser;
while ((fromServer = in.readLine()) != null) {
List<Person> people = new ArrayList<Person>();
Person person = new Person();
people = fromServer;
所以从外观上看,我无法通过此套接字方法传递对象。 json会做我需要的吗?我只是不想再花一天时间编写对我不起作用的东西。我要做的就是拥有一个我的服务器可以访问的数据库,服务器读取数据库并以我的对象的形式返回表数据。
【问题讨论】:
标签: android