这Json应该怎么解析?

qq_27665781 2016-03-18 03:55:57
[
[
{
"id": 435224,
"calcTime": "2016-03-16 20:20:52.0",
"unit": null,
"deviceCode": {
"id": 32,
"devicename": "主机1"
},
"value": 0
},
{
"id": 435220,
"calcTime": "2016-03-16 20:15:52.0",
"unit": null,
"deviceCode": {
"id": 32,
"devicename": "主机1"
},
"value": 0
},
{
"id": 435216,
"calcTime": "2016-03-16 20:10:52.0",
"unit": null,
"deviceCode": {
"id": 32,
"devicename": "主机1"
},
"value": 0
},
{
"id": 435212,
"calcTime": "2016-03-16 20:05:52.0",
"unit": null,
"deviceCode": {
"id": 32,
"devicename": "主机1"
},
"value": 0
},
{
"id": 435208,
"calcTime": "2016-03-16 20:00:52.0",
"unit": null,
"deviceCode": {
"id": 32,
"devicename": "主机1"
},
"value": 0
}
],
[
{
"id": 435225,
"calcTime": "2016-03-16 20:20:52.0",
"unit": null,
"deviceCode": {
"id": 33,
"devicename": "主机2"
},
"value": 0
},
{
"id": 435221,
"calcTime": "2016-03-16 20:15:52.0",
"unit": null,
"deviceCode": {
"id": 33,
"devicename": "主机2"
},
"value": 0
},
{
"id": 435217,
"calcTime": "2016-03-16 20:10:52.0",
"unit": null,
"deviceCode": {
"id": 33,
"devicename": "主机2"
},
"value": 0
},
{
"id": 435213,
"calcTime": "2016-03-16 20:05:52.0",
"unit": null,
"deviceCode": {
"id": 33,
"devicename": "主机2"
},
"value": 0
},
{
"id": 435209,
"calcTime": "2016-03-16 20:00:52.0",
"unit": null,
"deviceCode": {
"id": 33,
"devicename": "主机2"
},
"value": 0
}
],
[
{
"id": 435226,
"calcTime": "2016-03-16 20:20:52.0",
"unit": null,
"deviceCode": {
"id": 34,
"devicename": "主机3"
},
"value": 0
},
{
"id": 435222,
"calcTime": "2016-03-16 20:15:52.0",
"unit": null,
"deviceCode": {
"id": 34,
"devicename": "主机3"
},
"value": 0
},
{
"id": 435218,
"calcTime": "2016-03-16 20:10:52.0",
"unit": null,
"deviceCode": {
"id": 34,
"devicename": "主机3"
},
"value": 0
},
{
"id": 435214,
"calcTime": "2016-03-16 20:05:52.0",
"unit": null,
"deviceCode": {
"id": 34,
"devicename": "主机3"
},
"value": 0
},
{
"id": 435210,
"calcTime": "2016-03-16 20:00:52.0",
"unit": null,
"deviceCode": {
"id": 34,
"devicename": "主机3"
},
"value": 0
}
],
[
{
"id": 435227,
"calcTime": "2016-03-16 20:20:52.0",
"unit": null,
"deviceCode": {
"id": 35,
"devicename": "主机4"
},
"value": 0
},
{
"id": 435223,
"calcTime": "2016-03-16 20:15:52.0",
"unit": null,
"deviceCode": {
"id": 35,
"devicename": "主机4"
},
"value": 0
},
{
"id": 435219,
"calcTime": "2016-03-16 20:10:52.0",
"unit": null,
"deviceCode": {
"id": 35,
"devicename": "主机4"
},
"value": 0
},
{
"id": 435215,
"calcTime": "2016-03-16 20:05:52.0",
"unit": null,
"deviceCode": {
"id": 35,
"devicename": "主机4"
},
"value": 0
},
{
"id": 435211,
"calcTime": "2016-03-16 20:00:52.0",
"unit": null,
"deviceCode": {
"id": 35,
"devicename": "主机4"
},
"value": 0
}
]
]
...全文
128 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
AImmorta1 2016-03-18
  • 打赏
  • 举报
回复
jsonarray里面套着jsonarray,里面是jsonobject
qq_27665781 2016-03-18
  • 打赏
  • 举报
回复


业务需求是要用RestTemplate 解析Json的
qq_27665781 2016-03-18
  • 打赏
  • 举报
回复
引用 1 楼 bdmh 的回复:
这应该直接就是个数组,用JsonArray,或者用gson包解析成对象
真的非常感谢你,不过业务需求是要用 RestTemplate 解析的
luosiye312 2016-03-18
  • 打赏
  • 举报
回复
先定义实体类:
public class Bean {
	
	public class BeanChild2 {
		String id;
		String calcTime;
		String unit;
		BeanChild deviceCode;
		int value;

		public int getValue() {
			return value;
		}

		public void setValue(int value) {
			this.value = value;
		}

		public String getId() {
			return id;
		}

		public void setId(String id) {
			this.id = id;
		}

		public String getCalcTime() {
			return calcTime;
		}

		public void setCalcTime(String calcTime) {
			this.calcTime = calcTime;
		}

		public String getUnit() {
			return unit;
		}

		public void setUnit(String unit) {
			this.unit = unit;
		}

		public BeanChild getDeviceCode() {
			return deviceCode;
		}

		public void setDeviceCode(BeanChild deviceCode) {
			this.deviceCode = deviceCode;
		}

	}

	public class BeanChild {
		String id;
		String devicename;

		public String getId() {
			return id;
		}

		public void setId(String id) {
			this.id = id;
		}

		public String getDevicename() {
			return devicename;
		}

		public void setDevicename(String devicename) {
			this.devicename = devicename;
		}
	}

}
然后,JsonArray解释数组,定义的时候,这样定义:
List<ArrayList<BeanChild2>> jsonObject;
这样就可以了。
bdmh 2016-03-18
  • 打赏
  • 举报
回复
这应该直接就是个数组,用JsonArray,或者用gson包解析成对象

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧