开发者社区> 问答> 正文

Android 这Json应该怎么解析呢?【大家别嫌少,只有这点了】

是用的RestTemplate解析

图片说明
screenshot

[
 [
 {
 "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
 }
 ]
 ]

展开
收起
杨冬芳 2016-07-07 14:28:24 1741 0
1 条回答
写回答
取消 提交回答
  • IT从业

    你这是json数组呀,参考下这个。
    import org.json.JSONArray;

    import org.json.JSONObject;
    //jsonData的数据格式:[{ "id": "27JpL~jd99w9nM01c000qc", "version": "abc" },{ "id": "27JpL~j6UGE0LX00s001AH", "version": "bbc" },{ "id": "27JpL~j7YkM0LX01c000gt", "version": "Wa_" }]
    JSONArray arr = new JSONArray(jsonData);
    for (int i = 0; i < arr.length(); i++) {

    JSONObject temp = (JSONObject) arr.get(i);  
    String id = temp.getString("id");  
    String id = temp.getString("version");  

    }

    有一篇博客,http://blog.csdn.net/dwarven/article/details/7561563,参考下
    
    2019-07-17 19:52:47
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载

相关镜像