package com.example.androidjsonrpc;import java.util.List;import org.alexd.jsonrpc.JSONRPCClient;import org.alexd.jsonrpc.JSONRPCException;import org.alexd.jsonrpc.JSONRPCParams.Versions;import com.alibaba.fastjson.JSON;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}public void run(View view){new Thread(new Runnable() {@Overridepublic void run() {runinthread();}}).start();}public void runinthread(){//https://code.google.com/p/android-json-rpc/downloads/list//http://www.oschina.net/p/android-json-rpcJSONRPCClient client = JSONRPCClient.create("http://10.0.0.107/json_server/server.php",Versions.VERSION_2);client.setConnectionTimeout(2000);client.setSoTimeout(2000);try {  String string = client.callString("fuck","android谷歌",15,32);  Log.i("androidjsonrpc", "fuck="+string);  int i = client.callInt("add", 56, 25);  Log.i("androidjsonrpc", i+"");    //Student student=(Student) client.call("getstudent",  new Student(1,"name",123));  //Log.i("androidjsonrpc", student.toString()); // Log.i("androidjsonrpc", client.call("getstudent",  new Student(1,"name",123)).toString()); // Log.i("androidjsonrpc", client.call("getstudents",  "xx").toString());  String str=client.callString("getstudent",  new Student(1,"name",123));  Log.i("androidjsonrpc", str);    //fastjson 转换json字符串为对象  Student student=JSON.parseObject(str, Student.class);  Log.i("androidjsonrpc", student.toString());    str=client.callString("getstudents",  "xx");  Log.i("androidjsonrpc", str);    //使用到fastjson  转换json数组为list对象  List students=JSON.parseArray(str, Student.class);  Log.i("androidjsonrpc", students.toString());    }catch (JSONRPCException e){  e.printStackTrace();}}}

更多相关文章

  1. Android中的Context对象
  2. Android webview与js 交换JSON对象数据
  3. android 上 webkit js 扩展之全局本地对象实现步骤
  4. android Parcelable接口序列化对象
  5. android 反转字符串
  6. 【Android 初学】10、Intent对象的使用
  7. Android EditText 共用TextWatcher,在TextWatcher中确定对应的被
  8. Android 时间对象操作工具类
  9. Android 字符串格式化 千位符

随机推荐

  1. 这是快/最好?选择*或选择column1、colum2
  2. SQL0973N在 "" 堆中没有足够的存储器
  3. mysql优化---in型子查询,exists子查询,from
  4. MySql常用命令总结
  5. MYSQL 多表联合查询并分组的问题?
  6. mybatis中mysql多条件查询
  7. 怎样在办公网络通过跳板机获取生产环境的
  8. PLSQL乱码解决方案
  9. mysql每天凌晨0点准时启动taskeng.exe如
  10. 50个查询系列-第9个查询:查询所有课程成绩