目录
-T json
json JSON 文件格式。它可以与 -j 或 -J 一起使用来指定要包含哪些协议,或与 -x 选项一起使用来包含原始十六进制编码的数据包数据。使用示例
tshark -T json -r file.pcap
tshark -T json -j “http tcp ip” -x -r file.pcap
重复键名问题
比如tls.handshake.ciphersuites字段,表示支持的密码套件。tshark在打印输入出是会出现重复键名,如果此时直接用php中的json_decode处理,那么只会剩下最后一个值,因为php中不支持JSON键名重复。
//...
"tls.handshake.ciphersuites": {
"tls.handshake.ciphersuite": "0xdada",
"tls.handshake.ciphersuite": "0x1301",
"tls.handshake.ciphersuite": "0x1302",
"tls.handshake.ciphersuite": "0x1303",
"tls.handshake.ciphersuite": "0xc02b",
"tls.handshake.ciphersuite": "0xc02f",
"tls.handshake.ciphersuite": "0xc02c",
"tls.handshake.ciphersuite": "0xc030",
"tls.handshake.ciphersuite": "0xcca9",
"tls.handshake.ciphersuite": "0xcca8",
"tls.handshake.ciphersuite": "0xc013",
"tls.handshake.ciphersuite": "0xc014",
"tls.handshake.ciphersuite": "0x009c",
"tls.handshake.ciphersuite": "0x009d",
"tls.handshake.ciphersuite": "0x002f",
"tls.handshake.ciphersuite": "0x0035"
},
//...
JSON 键名重复是否允许?
来自知乎的评论:
作者:Milo Yip
链接:https://www.zhihu.com/question/373213978/answer/1026517650
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
ECMA-404 §6:The JSON syntax does not impose any restrictions on the strings used as names, does not require that name strings be unique, and does not assign any significance to the ordering of name/value pairs. These are all semantic considerations that may be defined by JSON processors or in specifications defining specific uses of JSON for data interchange.
标准明确写了名字不要求唯一。
RFC 8259 §4:An object whose names are all unique is interoperable in the sense that all software implementations receiving that object will agree on the name-value mappings. When the names within an object are not unique, the behavior of software that receives such an object is unpredictable. Many implementations report the last name/value pair only. Other implementations report an error or fail to parse the object, and some implementations report all of the name/value pairs, including duplicates.
最新 RFC 说,使用重复名字可能导致不同软件有不同行为。这算是「允许」但不建议吧。
P. S. RapidJSON 允许名字重复。
个人看法
- 如果只是作为文本格式存储或者输出,则没影响。
比如查看时可以编辑器进行自动缩进
- 如果需要被解析后处理,重复键名是个灾难
例如php的json_decode ,js 的JSON.pare。都无法会把前面重复的键名覆盖掉
php该如何处理
参考
rfc8259