问题描述
- 用java的谷歌库gson解析JSON,如下的json数据,该如何定义java类??
-
求高人指点,用java的谷歌库gson解析JSON,如下的json数据,该如何定义java类?? 在线等...............{
"00:00:8e:d7:ba:ac:88:47": {
"flow-mod-3": {
"version": 1,
"type": "FLOW_MOD",
"length": 72,
"xid": 0,
"match": {
"dataLayerDestination": "00:00:00:00:00:00",
"dataLayerSource": "00:00:00:00:00:00",
"dataLayerType": "0x0000",
"dataLayerVirtualLan": -1,
"dataLayerVirtualLanPriorityCodePoint": 0,
"inputPort": 1,
"networkDestination": "0.0.0.0",
"networkDestinationMaskLen": 0,
"networkProtocol": 0,
"networkSource": "0.0.0.0",
"networkSourceMaskLen": 0,
"networkTypeOfService": 0,
"transportDestination": 0,
"transportSource": 0,
"wildcards": 4194302
},
"cookie": 45035997351236010,
"command": 0,
"idleTimeout": 0,
"hardTimeout": 0,
"priority": -32768,
"bufferId": -1,
"outPort": -1,
"flags": 0,
"actions": [ ],
"lengthU": 72
}
},
"00:00:8e:d7:ba:ac:88:46": {
"flow-mod-1": {
"version": 1,
"type": "FLOW_MOD",
"length": 72,
"xid": 0,
"match": {
"dataLayerDestination": "00:00:00:00:00:00",
"dataLayerSource": "00:00:00:00:00:00",
"dataLayerType": "0x0000",
"dataLayerVirtualLan": -1,
"dataLayerVirtualLanPriorityCodePoint": 0,
"inputPort": 1,
"networkDestination": "0.0.0.0",
"networkDestinationMaskLen": 0,
"networkProtocol": 0,
"networkSource": "0.0.0.0",
"networkSourceMaskLen": 0,
"networkTypeOfService": 0,
"transportDestination": 0,
"transportSource": 0,
"wildcards": 4194302
},
"cookie": 45035997351236010,
"command": 0,
"idleTimeout": 0,
"hardTimeout": 0,
"priority": -32768,
"bufferId": -1,
"outPort": -1,
"flags": 0,
"actions": [ ],
"lengthU": 72
},
"flow-mod-2": {
"version": 1,
"type": "FLOW_MOD",
"length": 72,
"xid": 0,
"match": {
"dataLayerDestination": "00:00:00:00:00:00",
"dataLayerSource": "00:00:00:00:00:00",
"dataLayerType": "0x0000",
"dataLayerVirtualLan": -1,
"dataLayerVirtualLanPriorityCodePoint": 0,
"inputPort": 1,
"networkDestination": "0.0.0.0",
"networkDestinationMaskLen": 0,
"networkProtocol": 0,
"networkSource": "0.0.0.0",
"networkSourceMaskLen": 0,
"networkTypeOfService": 0,
"transportDestination": 0,
"transportSource": 0,
"wildcards": 4194302
},
"cookie": 45035997351236010,
"command": 0,
"idleTimeout": 0,
"hardTimeout": 0,
"priority": -32768,
"bufferId": -1,
"outPort": -1,
"flags": 0,
"actions": [ ],
"lengthU": 72
}
}
}
解决方案
你先弄明白json格式吧,每一对大括号,基本可以定义一个类,蹭蹭嵌套,json的每个key就是字段名
解决方案二:
你这种的无法解析,你让服务器给你改一下格式,
解决方案三:
当做Map还可以。大括号你可以看成是Map,或者是类的属性。而中括号你可以看作是List或者是数组。也就是一对类的集合。
解决方案四:
To Code_M0nkey :请多指点。应该是你的思路。