- 浏览: 506160 次
- 性别:
- 来自: 山东
文章分类
最新评论
-
wjpiao:
...
HttpClient4模拟登录回贴 -
spring_springmvc:
可以参考最新的文档:如何在eclipse jee中检出项目并转 ...
Maven-pom.xml -Dependency Scope 区别 -
7454103:
京东通信此次推出的特权卡名为“自由行”,主打无套餐、无合约、无 ...
判断手机号码是否合法--正则 -
di1984HIT:
谢谢啊~学习了~
Maven Nexus 管理员密码重置 -
BigCat2013:
XMLFileUtil.getAttributeValue() ...
java调用sql XML配置文件 笔记
java中返回的JSON对象转换成List 用法
解析用法:
返回json字符串值代码如下:
解析用法:
//调用URL --分页 String str = CommonConstant.getPhotoAlbumByUserIdURL() + userid + "&pageNo=" + paginationDto.getPageNum() + "&pageSize=" + paginationDto.getRowsPerPage(); HttpClient client = new HttpClient(); PostMethod method = new PostMethod(str); List<PhotoAlbumVO> photoAlbumList = new ArrayList<PhotoAlbumVO>(); try { client.executeMethod(method); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String returnJson = ""; try { returnJson = method.getResponseBodyAsString();//返回json字符串值 System.out.println("---------------------returnJson---------------------------------" + returnJson); if(returnJson != null && returnJson != ""){ String strJson = returnJson.replace("?(", "").replace(")", "").replace(";", ""); if(strJson.startsWith("{")){ JSONObject jsonObject = JSONObject.fromObject(strJson); String code = jsonObject.getString("code").toString(); if("200".equals(code)){ JSONArray jsonArray = JSONArray.fromObject(jsonObject.get("result")); JSONObject jsonObj = jsonArray.getJSONObject(0); JSONArray dataArray = JSONArray.fromObject(jsonObj.get("data")); for (int i = 0, len = dataArray.size(); i < len; i++) { PhotoAlbumVO vo = new PhotoAlbumVO(); JSONObject jsonVideo = dataArray.getJSONObject(i); vo.setId(jsonVideo.get("id").toString()); vo.setUserid(jsonVideo.get("userid").toString()); vo.setTitle(jsonVideo.get("title").toString()); vo.setIntro(jsonVideo.get("intro").toString()); vo.setCoverPath(jsonVideo.get("cover_path").toString()); vo.setType(Integer.parseInt(jsonVideo.get("type").toString())); vo.setNumberPhoto(Integer.parseInt(jsonVideo.get("number_photo").toString())); vo.setCreatedTime(DateTimeUtils.parseFullDateTime(DateUtil.getDateTimeByMillisecond(jsonVideo.get("created_time").toString()))); vo.setUpdatedTime(DateTimeUtils.parseFullDateTime(DateUtil.getDateTimeByMillisecond(jsonVideo.get("updated_time").toString()))); photoAlbumList.add(vo); } JSONArray pageArray = JSONArray.fromObject(jsonObj.get("page")); JSONObject pagerObj = pageArray.getJSONObject(0); JSONArray pagerArray = JSONArray.fromObject(pagerObj.get("pager")); JSONObject pagerObj1 = pagerArray.getJSONObject(0); paginationDto.setTotalRowNum(Long.valueOf(pagerObj1.get("pageSum").toString())); } } } } catch (IOException e1) { e1.printStackTrace(); }finally{ //使用完成后要释放链接 method.releaseConnection(); } System.out.println("===========================================size"+photoAlbumList.size()); return photoAlbumList;
返回json字符串值代码如下:
引用
{"code":"200","message":"","header":"","result":{"data":[
{"id":"00010900020127","userid":"560110","title":"\u9ed8\u8ba4\u76f8\u518c","intro":"\u6211\u7684\u9ed8\u8ba4\u76f8\u518c","location":"","tags":null,"editor_tags":null,"domain":null,"cover_path":"http:\/\/static.woyo.com\/img\/abcp\/common\/no_photo.jpg","type":"1","sort_order":"990","rank":"1","privilege_password":null,"comment_type":"2","is_share":"1","number_photo":"4","number_photo_checked":"4","number_commented":"0","number_hits":"2","photo_orders":"00010900020060,00010900020059,00010900020058,00010900020057,","created_time":"1281347526","updated_time":"1287049401","status":"3","checker_id":null,"checked_time":"0","is_deleted":"0","simpleTitle":"\u9ed8\u8ba4\u76f8\u518c","simpleIntro":"\u6211\u7684\u9ed8\u8ba4\u76f8\u518c","simpleLocation":"","cover_path_full":"http:\/\/static.woyo.com\/img\/abcp\/common\/no_photo.jpg"},
{"id":"00010900020136","userid":"560110","title":"2010","intro":"2010","location":"","tags":null,"editor_tags":null,"domain":"1","cover_path":"http:\/\/static.woyo.com\/img\/abcp\/common\/no_photo.jpg","type":"0","sort_order":"500","rank":"2","privilege_password":"111","comment_type":"2","is_share":"1","number_photo":"0","number_photo_checked":"0","number_commented":"0","number_hits":"0","photo_orders":null,"created_time":"1286879434","updated_time":"1286879434","status":"0","checker_id":null,"checked_time":"0","is_deleted":"0","simpleTitle":"2010","simpleIntro":"2010","simpleLocation":"","cover_path_full":"http:\/\/static.woyo.com\/img\/abcp\/common\/no_photo.jpg"}],
"page":{"pager":{"pageUnit":"\u6761","pageTit":"\u8bb0\u5f55","pageBeginNum":1,"pageEndNum":2,"pageSum":2,"pageNow":1,"pagePrevNum":1,"pageNextNum":1,"pageFirstNum":1,"pageLastNum":1,"pageAb":1,"pageAe":1,"callJs":"pageJs"}}}}
{"id":"00010900020127","userid":"560110","title":"\u9ed8\u8ba4\u76f8\u518c","intro":"\u6211\u7684\u9ed8\u8ba4\u76f8\u518c","location":"","tags":null,"editor_tags":null,"domain":null,"cover_path":"http:\/\/static.woyo.com\/img\/abcp\/common\/no_photo.jpg","type":"1","sort_order":"990","rank":"1","privilege_password":null,"comment_type":"2","is_share":"1","number_photo":"4","number_photo_checked":"4","number_commented":"0","number_hits":"2","photo_orders":"00010900020060,00010900020059,00010900020058,00010900020057,","created_time":"1281347526","updated_time":"1287049401","status":"3","checker_id":null,"checked_time":"0","is_deleted":"0","simpleTitle":"\u9ed8\u8ba4\u76f8\u518c","simpleIntro":"\u6211\u7684\u9ed8\u8ba4\u76f8\u518c","simpleLocation":"","cover_path_full":"http:\/\/static.woyo.com\/img\/abcp\/common\/no_photo.jpg"},
{"id":"00010900020136","userid":"560110","title":"2010","intro":"2010","location":"","tags":null,"editor_tags":null,"domain":"1","cover_path":"http:\/\/static.woyo.com\/img\/abcp\/common\/no_photo.jpg","type":"0","sort_order":"500","rank":"2","privilege_password":"111","comment_type":"2","is_share":"1","number_photo":"0","number_photo_checked":"0","number_commented":"0","number_hits":"0","photo_orders":null,"created_time":"1286879434","updated_time":"1286879434","status":"0","checker_id":null,"checked_time":"0","is_deleted":"0","simpleTitle":"2010","simpleIntro":"2010","simpleLocation":"","cover_path_full":"http:\/\/static.woyo.com\/img\/abcp\/common\/no_photo.jpg"}],
"page":{"pager":{"pageUnit":"\u6761","pageTit":"\u8bb0\u5f55","pageBeginNum":1,"pageEndNum":2,"pageSum":2,"pageNow":1,"pagePrevNum":1,"pageNextNum":1,"pageFirstNum":1,"pageLastNum":1,"pageAb":1,"pageAe":1,"callJs":"pageJs"}}}}
发表评论
-
easyui combobox下拉效果 可输入 模糊查询
2015-12-24 13:03 18202<link rel="stylesheet&q ... -
字符串编码生成实现
2015-08-06 09:28 839//为长度为22的字符串 编码生成实现 //格式:XAAA ... -
eclipse设置默认指向/src/main/webapp目录
2015-02-11 09:28 3500改配置文件, 打开.setting 文件夹下的 org.ecl ... -
判断手机号码是否合法--正则
2014-10-30 16:26 1748import java.util.regex.Matc ... -
JAVA集合
2014-09-30 13:04 698ArrayList和LinkedList区别 1.Ar ... -
乱码???
2014-09-12 16:57 999http://blog.csdn.net/youyue/art ... -
APACHE+TOMCAT配置负载均衡
2014-09-09 09:37 1308目标: 使用 apache 和 tomcat 配置一个可以应 ... -
日期格式化取月日
2014-08-13 14:18 869日期格式化 SimpleDateFormat sdf = n ... -
java实现获取各种浏览器版本号及类型
2014-07-22 13:28 4660引用public Map<String,String&g ... -
两个数的百分比
2014-02-25 11:50 1056public static void main(String[ ... -
java补全
2014-02-21 13:27 1001import java.text.NumberFormat; ... -
oracle日期相减
2014-02-12 16:43 1532oracle日期相减 --MONTHS_BETWEEN(dat ... -
PermGen space及其解决方法
2014-01-23 10:00 1241-Xms256m -Xmx1024m -XX:PermSize ... -
webservcie-wsimport
2013-08-30 12:32 826wsimport wsimport是在JDK的bin目录下的 ... -
tomcat服务启动取IP4地址设置
2013-06-17 15:59 13161.Open launch configuration 2. ... -
Windows反向代理安装配置(双机)笔记
2013-06-07 09:05 3353引用 下载 httpd-2.2.22-win32-x86-no ... -
Maven-pom.xml -Dependency Scope 区别
2013-06-06 09:38 6098如下图报错,找错 1. 找 ... -
webservice调用异常
2013-06-03 16:27 1305Exception in thread "mai ... -
spring防止内存泄露配置
2013-05-07 15:43 888<!-- Spring 刷新Introspector ... -
删除字符串中带中文的指定字符
2013-04-23 08:50 1102public class Test { /** ...
相关推荐
二、Java类对象到JSON转换 1. 将Java对象转换为JSON字符串,同样使用`ObjectMapper`: ```java User john = new User(1, "John", "john@example.com"); String johnJson = mapper.writeValueAsString(john); ``` ...
这个过程涉及将JSON对象转换为`JSONObject`,创建一个类映射,然后使用`toBean()`方法将JSON对象转换为对应的Java实例。注意,为了支持多层List集合,我们需要确保所有相关的Java类都有对应的getter和setter方法,...
标题中的“使用json-lib将java对象转换成json字符串”指的是在Java编程中,利用json-lib这个库来将Java对象转化为JSON格式的字符串。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,广泛用于前后端...
可能包含的方法有`toJson()`(将Java对象转换为JSON字符串)、`fromJson()`(将JSON字符串解析为Java对象)、`convertToMap()`(将JSON字符串转换为Map)以及`convertToList()`(将JSON字符串转换为List)等。...
在Java中,我们经常需要将JSON字符串与Java对象进行相互转换,以便于数据的传输和处理。本篇文章将详细探讨这个过程,以及如何使用常见的Java JSON库,如Gson和Jackson,进行JSON与Java对象的转换。 首先,让我们...
总之,Java中对象数组与JSON之间的转换是通过使用适当的库和方法来完成的。选择哪种库取决于项目的需求和偏好。无论是将Java对象数组转换为JSON,还是将JSON转换为Java对象数组,掌握这些转换技巧对于处理Web服务、...
"JSON 转换为 List 涉及 Java 和 Spring Boot" ...我们首先讨论了 JSON 转换为 List 的必要性,然后介绍了使用 Java 和 Spring Boot 将 JSON 转换为 List 的方法。最后,我们解析了 `parseJSON2List` 方法的实现细节。
该方法首先使用XMLSerializer将xml字符串转换为XML对象,然后使用JSONSerializer将XML对象转换为JSON对象。 map和json之间的转换 map和json之间的转换也可以通过使用json-lib库来实现。例如,mapToJson方法将Map...
Java与JSON对象间转换的知识点涉及到Java中对象与JSON格式数据之间的互相转换方法,这是在Web开发和数据交互中常见的需求。在Java中处理JSON数据主要依靠一些第三方库,json-lib是其中之一,它能够将Java对象转换成...
除了将JSON转换为Java对象,我们还可以使用`ObjectMapper`将Java对象转换回JSON字符串,这对于前端展示或存储数据非常有用: ```java String json = mapper.writeValueAsString(outerObject); ``` 6. **异常...
首先,我们需要一个库来处理JSON转换,这里提到的"json-lib"是一个广泛使用的Java JSON库,提供了多种类型到JSON的转换功能。在Java中,有两种主要方式实现对象到JSON的转换:使用`org.json`库和使用`json-lib`库。...
Java对象与JSON对象之间的转换是数据交换和网络通信中常见的需求。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,易于人阅读和编写,同时也易于机器解析和生成。在Java开发中,我们通常使用一些库...
在上述代码中,`readValue`方法用于将JSON字符串转换为指定的Java类型。通过这种方式,我们可以轻松地处理复杂的JSON结构,包括多层嵌套和List集合。 此外,Jackson库还提供了其他功能,如反序列化配置、类型转换、...
在Java编程中,经常需要将Java对象转换为JSON对象,反之亦然,以便于数据的序列化、网络传输或存储。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,易于人阅读和编写,同时也方便机器解析和生成。...
在给定的“利用java反射将json字符串转成对象”的主题中,我们将深入探讨如何借助反射机制将JSON字符串转换为Java对象。 首先,我们需要了解JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,易于人...
此外,为了让SpringMVC知道如何将你的Java对象转换为JSON,你需要在你的模型类上使用Jackson的注解,例如`@JsonProperty`、`@JsonInclude`、`@JsonIgnore`等。这些注解可以帮助控制哪些属性应该被包含在JSON中,哪些...
在Java编程中,将对象转换为JSON(JavaScript Object Notation)格式是常见的需求,反之亦然。JSON是一种轻量级的数据交换格式,易于人阅读和编写,同时也方便机器解析和生成。在Java中,可以使用各种库来实现这种...
在Java 8中将List转换为Map对象方法 在Java 8中,将List转换为Map对象是一种非常实用的技术,特别是在处理大规模数据时非常有用。本文将详细介绍在Java 8中将List转换为Map对象的方法,并提供了多种实现方式。 ...
本文将详细介绍几种常用的在Java中构建JSON对象的方法,并通过具体的代码示例进行说明。 #### 一、使用`net.sf.json.JSONObject` 在早期的Java开发中,`net.sf.json.JSONObject`是一个非常流行的库,用于创建和...