Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获取json中重复元素的第一个?_Json_Python 3.x_Wireshark - Fatal编程技术网

如何获取json中重复元素的第一个?

如何获取json中重复元素的第一个?,json,python-3.x,wireshark,Json,Python 3.x,Wireshark,这是我正在使用的wireshark json的一个压缩示例。当我使用Python3循环json时,它只返回最后一个wlan元素,我需要第一个。如何访问该元素中的数据 当我尝试直接访问时,它还获得第二个wlan元素 ie printjson[0][wlan],返回第二个wlan元素。也许您不应该使用重复的键 但您仍然可以使用JSONDecoder: 该示例的JSON语法无效。看起来更像python中的词典。 [ { frame: {data,data} radiotap: {data,d

这是我正在使用的wireshark json的一个压缩示例。当我使用Python3循环json时,它只返回最后一个wlan元素,我需要第一个。如何访问该元素中的数据

当我尝试直接访问时,它还获得第二个wlan元素
ie printjson[0][wlan],返回第二个wlan元素。

也许您不应该使用重复的键

但您仍然可以使用JSONDecoder:


该示例的JSON语法无效。看起来更像python中的词典。
[
 {
  frame: {data,data}
  radiotap: {data,data}
  wlan: {data,data}
  wlan: {data,data}strong text
 }
]
from json import JSONDecoder


def met(a):
    return a


json="""{
  "frame": {"a": 10},
  "radiotap": {"b": 10},
  "wlan": {"c": 10},
  "wlan": {"d": 10}
 }
 """


for i in JSONDecoder(object_pairs_hook=met).decode(json):
    print(i)