我已经构建了一个Java服务器应用程序,并尝试让我的Android应用程序与其通信。在阅读Android客户端服务器通信之后,我尝试了套接字示例。但是,我遇到了困难,因为在服务器端我可以返回我的对象数组,但在客户端端我无法检索它,因为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;
看起来我无法通过这个socket方法传递一个对象。json能满足我的需求吗?我不想再浪费一天的时间编写不起作用的东西。我只是想拥有一个数据库,让我的服务器可以访问该数据库,服务器读取数据库并以我的对象形式返回表格数据。