android jsonrpc 使用实例
2015-06-09 10:49
393 查看
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 { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void run(View view) { new Thread(new Runnable() { @Override public void run() { runinthread(); } }).start(); } public void runinthread() { //https://code.google.com/p/android-json-rpc/downloads/list //http://www.oschina.net/p/android-json-rpc JSONRPCClient 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<Student> students=JSON.parseArray(str, Student.class); Log.i("androidjsonrpc", students.toString()); } catch (JSONRPCException e) { e.printStackTrace(); } } }
相关文章推荐
- Android Studio项目中导入开源库的方法
- html实现类似android的tab切换页面
- Android sdk content loader 0%的解决方案
- Android EventBus实战
- Android Ant打包及其环境变量配置
- Android 自定义View使用示例(二)
- android实习期日常笔记(二)
- Android GridView实现滚动到指定位置的方法
- 传智播客Android7.16日入驻大广州
- android学习之---基本问题1
- AndroidのListView包含CheckBox时滑动丢失选中状态的解决
- Android NDK (学习笔记五) —— java层和native层进行字符串的交互处理
- Android 利用sharepreference保存应用程序状态
- Android Design Support Library使用详解
- java.lang.ClassCastException: 。。。$LayoutParams cannot be cast to android.widget.LinearLayout$Layout
- Android调用系统相机拍照并获取图片
- android中Parcelable接口的使用
- Android 调用QQ登录
- android 自定义view 圆形进度条
- android开发环境安装与配置