平时用 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 了。