jackson 解析结合类(需要传入Class, 和 Class.Class, 回调方法是List<Class>)
import java.util.HashMap;
import java.util.List; import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.type.TypeFactory;
import org.codehaus.jackson.type.JavaType; import com.leighyu.utils.Constants; public class AsyncGetProductCategories<T> implements Runnable { private final Class<T> type;
public interface OnFinishListener<T> {
public void onFinish(List<T> t);
}
private OnFinishListener<T> onFinishListener;
public void setFinishListener(OnFinishListener<T> onFinishListener) {
this.onFinishListener = onFinishListener;
} private String url;
private HashMap<String, String> params;
public AsyncGetProductCategories(Class<T> type) {
this.type = type;
this.url = Constants.URL + "productcategorylist/getalllevelone.html";
HashMap<String, String> params = new HashMap<String, String>();
params.put("testkey", "testvalue");
this.params = params;
} @Override
public void run() {
try {
String result = WebUtil.httpPostJson(this.url, this.params); ObjectMapper mapper = new ObjectMapper();
JavaType listType = TypeFactory.collectionType(List.class, type);
List<T> entities = mapper.readValue(result, listType);
if(onFinishListener != null) {
onFinishListener.onFinish(entities);
}
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
AsyncGetProductCategories<ProductCategoryEntity> agpc =
new AsyncGetProductCategories<ProductCategoryEntity>(ProductCategoryEntity.class);
agpc.setFinishListener(new OnFinishListener<ProductCategoryEntity>(){
@Override
public void onFinish(final List<ProductCategoryEntity> entities) {
activity.runOnUiThread(new Runnable()
{
@Override
public void run() {
drawLevelOne(entities);
mProgressDialog.dismiss();
}
});
}
}); new Thread(agpc).start();
jackson 解析结合类(需要传入Class, 和 Class.Class, 回调方法是List<Class>)的更多相关文章
- jackson 解析json含有不规则的属性的json字符串的方法
对于json中含有点号,等其它特殊的,不是规范的java变量名的字符,能够使用一个注解来处理. 贴代码: import com.fasterxml.jackson.annotation.JsonPro ...
- 爬虫代码实现五:解析所有分页url并优化解析实现类
如图,我们进入优酷首页,可以看到电视剧列表,我们称这个页面为电视剧列表页,而点击进入某个电视剧,则称为电视剧详情页.那么如何获取所有分页以及对应的详情页呢,通过下面的分页得到. 因此,首先,我们将St ...
- 记一次FastJSON和Jackson解析json时遇到的中括号问题
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jadyer/article/details/24395015 完整版见https://jadyer. ...
- C#字符串数组排序 C#排序算法大全 C#字符串比较方法 一个.NET通用JSON解析/构建类的实现(c#) C#处理Json文件 asp.net使用Jquery+iframe传值问题
C#字符串数组排序 //排序只带字符的数组,不带数字的 private string[] aa ={ "a ", "c ", "b & ...
- JSON介绍及Android最全面解析方法(Gson、AS自带org.son、Jackson解析)
前言 今天,我们来介绍一下现今主流的数据交换格式-JSON! 相同作为主流为数据交换格式-XML,假设有兴趣能够阅读我写的XML及其DOM.SAX.PULL解析方法和对照 文件夹 定义 JavaScr ...
- Spring5源码解析6-ConfigurationClassParser 解析配置类
ConfigurationClassParser 在ConfigurationClassPostProcessor#processConfigBeanDefinitions方法中创建了Configur ...
- 解析ThreadPoolExecutor类是如何保证线程池正确运行的
摘要:对于线程池的核心类ThreadPoolExecutor来说,有哪些重要的属性和内部类为线程池的正确运行提供重要的保障呢? 本文分享自华为云社区<[高并发]通过源码深度解析ThreadPoo ...
- 【高并发】深度解析ScheduledThreadPoolExecutor类的源代码
在[高并发专题]的专栏中,我们深度分析了ThreadPoolExecutor类的源代码,而ScheduledThreadPoolExecutor类是ThreadPoolExecutor类的子类.今天我 ...
- 解析C#类中的构造函数
<解析C#类中的构造函数> 一. C#中的构造函数概述: C#中类包含数据成员和函数成员.函数成员提供了操作类中数据的某些功能,包括方法.属性.构造器和终结器.运算符和索引器. 构造函数 ...
随机推荐
- 在一个文件中有10G个整数,乱序排列,要求找出中位数
题目:在一个文件中有 10G 个整数,乱序排列,要求找出中位数.内存限制为 2G.只写出思路即可(内存限制为 2G的意思就是,可以使用2G的空间来运行程序,而不考虑这台机器上的其他软件的占用内存). ...
- FTP服务器简易有效的访问方法
访问FTP服务器传统的方法是使用专用的客户端程序,如CuteFTP,8UFTP等,也包括命令行的FTP客户端c:\windows\system32\ftp.exe程序. FTP服务器也有简易访问方法 ...
- 利用 Composer 一步一步构建自己的 PHP 框架(四)——使用 ORM
本教程示例代码见 https://github.com/johnlui/My-First-Framework-based-on-Composer 回顾 经过前三篇文章 基础准备 . 构建路由 和 设计 ...
- 结合源码看nginx-1.4.0之nginx事件驱动机制详解
目录 0. 摘要 1. nginx事件模块组织结构 2. nginx事件模块数据结构及类图 3. nginx事件模块运行机制 4. 练习:一个简单的事件驱动模块 5. 小结 6. 参考源码
- 为什么我要称自己为Javascript程序员
Aaron Griffin写了一篇精彩的牢骚文章,主要是关于各种框架和它们能把程序员从主要业务编程中抽离出来的功能特征.概括一下他的主要论点,当你成为了一个“Rails程序员”,你使用的是一种易于理解 ...
- Linux系统上安装mysql数据库
一:下载并且上传安装包到linux系统上 1:下载地址:http://dev.mysql.com/downloads/mysql/ 2:通过LeapFtp工具,将windows上的mysql安装包拷贝 ...
- rpmdb: BDB0113 错误
解决方法: rpm --rebuilddb yum clean all
- [改善Java代码]适时选择getDeclaredxxx和getxxx
Java的Class类提供了很多的getDeclaredxxx方法和getxxx方法,例如getDeclaredmethod和getMethod成对出现,getDeclaredConstructors ...
- SSH整合_struts.xml 模板
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "- ...
- hdu 4325 树状数组+离散化
思路:这题的思路很容易想到,把所有时间点离散化,然后按时间一步一步来,当到达时间i的时候处理所有在i处的查询. 这个代码怎一个挫字了得 #include<iostream> #includ ...