平时用 mac 的基本都接触过 plist 文件,它一般用作项目的配置文件,而 bplist 文件就是它的二进制形式。
如果需要解析 bplist 文件内容,可以参考 github 上的 plist2json项目,但如果直接执行程序,会提示 map 下 key 不允许改变:
lucas@lucasdeMacBook-Pro plist2json % ll
total 112
-rw-r--r-- 1 lucas staff 1994 11 15 18:39 Info.plist
-rw-r--r-- 1 lucas staff 1062 11 15 18:39 LICENSE
-rw-r--r-- 1 lucas staff 6001 11 15 18:39 test.bplist
drwxr-xr-x 7 lucas staff 224 11 29 21:19 plist
-rw-r--r-- 1 lucas staff 767 11 15 18:39 readme.md
-rw-r--r-- 1 lucas staff 723 11 15 18:58 test.py
lucas@lucasdeMacBook-Pro plist2json % python3 test.py
Traceback (most recent call last):
File "test.py", line 28, in <module>
testBPlist()
File "test.py", line 20, in testBPlist
print(convertPlistToJson(content));
File "test.py", line 10, in convertPlistToJson
bplist = BPlist(plistContent)
File "/Users/lucas/www/plist2json/plist/bplist.py", line 30, in __init__
self.parseData()
File "/Users/lucas/www/plist2json/plist/bplist.py", line 60, in parseData
for key, val in obj.items():
RuntimeError: dictionary keys changed during iteration
lucas@lucasdeMacBook-Pro plist2json %
根据提示,第 60 行附近程序如下:
if type(obj) == dict:
for key, val in obj.items():
if type(key) == Index:
obj.pop(key)
obj[self.objectList[key.index]] = self.objectList[val.index]
此处只需将 map 改为 list ,即:
for key, val in list(obj.items()):
if type(key) == Index:
obj.pop(key)
再重新执行程序就 ok 了。
本文档介绍了在解析bplist文件时遇到的问题,通过使用github上的plist2json项目,作者发现程序在尝试转换二进制plist到JSON时遇到了`dictionary keys changed during iteration`的错误。经过分析,问题出在代码尝试修改迭代中的字典。为解决这个问题,作者建议将迭代对象从字典改为列表,避免在迭代过程中修改字典。通过这个修改,程序得以正常执行。
7026

被折叠的 条评论
为什么被折叠?



