Gson字符串转换对象数组
public class Input
{
private String title;
private int formId;
private String content; public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public int getFormId() {
return formId;
} public void setFormId(int formId) {
this.formId = formId;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} @Override
public String toString() {
return "Input{" +
"title='" + title + '\'' +
", formId=" + formId +
", content='" + content + '\'' +
'}';
}
} String fromData ="[{\"title\":\"赚币和赏金可在哪查看\",\"formId\":292,\"content\":\"我的\"}, {\"title\":\"赚币有什么用?\",\"formId\":293,\"content\":\"可用于抽奖\"}, {\"title\":\"提现一般哪天处理?\",\"formId\":295,\"content\":\"每周一处理,周三到账\"}, {\"title\":\"任务审核周期多长?\",\"formId\":296,\"content\":\"一般不超过7天\"}, {\"title\":\"如何邀请好友(多选)\",\"formId\":297,\"content\":\"使用邀请码-扫描二维码-分享给好友\"}] "; Type type = new TypeToken<ArrayList<Input>>() {
}.getType(); Gson gson = new Gson();
ArrayList<Input> arrayList= gson.fromJson(fromData,type); for(Input input :arrayList)
{
System.out.println(input);
}
输出结果
Input{title='赚币和赏金可在哪查看', formId=292, content='我的'}
Input{title='赚币有什么用?', formId=293, content='可用于抽奖'}
Input{title='提现一般哪天处理?', formId=295, content='每周一处理,周三到账'}
Input{title='任务审核周期多长?', formId=296, content='一般不超过7天'}
Input{title='如何邀请好友(多选)', formId=297, content='使用邀请码-扫描二维码-分享给好友'}
Gson字符串转换对象数组的更多相关文章
- JS - 字符串转换成数组,数组转换成字符串
1.字符串转换成数组: var arr = "1, 2, 3, 4, 5, 6"; arr.split(","); // ["1",&quo ...
- JS-如何把字符串转换成数组
var a = "1,22,33,44"; // 字符串 var b = a.split(","); // 将字符串按照","分割,存入数组 ...
- Json数组转换字符串、字符串转换原数组......
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- json字符串转换对象的方法1
为了方便读者了解json的使用,读者直接粘贴下面代码看效果即可: var json1 = {'name':'小李','age':'11','sex':'女'};console.log(json1.na ...
- json字符串转换对象的方法
为了方便读者了解json的使用,读者直接粘贴下面代码看效果即可: var json1 = {'name':'小李','age':'11','sex':'女'}; console.log(json1.n ...
- 前台发送字符串给后台,格式为(a,b,c,d),后台将字符串转换成数组遍历后进而更新CheckId
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Configuration; u ...
- php数组和字符串转换
PHP 中由于数组和字符串这两种变量类型是如此常用,以至于 PHP 具有两个函数,可以在字符串和数组之间互相进行转换. $array=explode(separator,$string); $stri ...
- php数组与字符串转换
1.将字符串转换成数组的几个函数: (1)explode(separate,string) 示例:$str = "Hello world It's a beautiful day" ...
- JavaScript学习笔记3之 数组 & arguments(参数对象)& 数字和字符串转换 & innerText/innerHTML & 鼠标事件
一.Array数组 1.数组初始化(Array属于对象类型) /*关于数组的初始化*/ //1.创建 Array 对象--方法1: var arr1=[]; arr1[0]='aa';//给数组元素赋 ...
随机推荐
- Django first()和last() F查询以及Q查询
一.first()和last() 分别返回queryset的第一项与最后一项,具体用法如下: p = Blog.objects.order_by('title').first() 等同于: try: ...
- java_第一年_JavaWeb(4)
HttpServletResponse对象 向客户端发送数据的方法: 通过getOutputStream()方法得到OutputStream对象,再通过write发送 通过getWriter()方法得 ...
- PEP8规范总结
PEP8规范总结 代码编排 1 缩进.4个空格的缩进(编辑器都可以完成此功能),不使用Tap,更不能混合使用Tap和空格. 2 每行最大长度79,换行可以使用反斜杠,最好使用圆括号.换行点要在操作符的 ...
- windows下安装oracle11g
第一步:一定要先做这一步. Oracle11g 安装过程出现提示:未找到文件 D:\app\Administrator\product\11.2.0\dbhome_2\owb\external\oc4 ...
- Panabit镜像功能配合wireshark抓包的方法
Panabit镜像功能配合wireshark抓包的方法 Panabit的协议识别都是基于数据包的特征,因此捕获数据包样本是我们进行识别第一步要做的事情.下面就和大家说一下如何捕获网络应用的数据包. 到 ...
- CHEVP算法(Canny/Hough Estimation of Vanishing Points)
这个算法是汪悦在 Lane detection and tracking using B-spline中提出来的.他在这篇论文中主要用的是B-spline模型,这个模型的主要优点是鲁棒性好,可以针对不 ...
- C#使用Process启动exe程序,不弹出控制台窗口的方法
背景:使用wkhtmltopdf工具将html转换成pdf时,这个工具在进行转换时会弹出命令行窗口显示转换过程,但是在项目运行时弹出服务器突然弹出控制台窗口会很奇怪,尤其是当转换多个时.解决这个问题 ...
- centos7安装rabbitmq简单方式
1,安装rabbitmq前要准备的基础环境 yum install build-essential openssl openssl-devel unixODBC unixODBC-devel make ...
- [SDOI2017]数字表格 (莫比乌斯反演)
链接:https://ac.nowcoder.com/acm/problem/20391来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言52428 ...
- Android_Refrogit与RxJava结合使用(转)
Refrogit与RxJava结合的使用 达到了非常简单就可以完成请求网络 一:1.0示例: 1.导入依赖 compile 'io.reactivex:rxjava:1.3.4'compile ...